Count the union of overlapping sets without double counting:
|A∪B∪C| = Σ|A| − Σ|A∩B| + |A∩B∩C|.
The left panel lights each Venn term as it is added (green) or subtracted (red).
The right panel runs the same alternating sum as a bitmask subset enumeration to count
integers in [1, N] divisible by at least one of your numbers, with intersections sized by floor(N / lcm).
step 0
Venn regions — alternating add / subtract
Press Step to begin building the union formula.
term added (+) term subtracted (−) current term
current subset—
|subset| → sign—
running union0
Bitmask subsets — divisible by at least one
answer so far: 0 integers in [1, 100] divisible by ≥1 of {6,10,15}
mask
subset
|S|
lcm
floor(N/lcm)
sign
running
This visualization runs PIE two ways at once. Both reach the same alternating sum:
odd-size subsets add, even-size subtract (union form).
Complexity
Operation
Cost
Note
Full PIE over n sets
O(2ⁿ · n)
2ⁿ subsets, n ops each
With subset-tree reuse
O(2ⁿ)
one incremental lcm/AND per node
DFS-pruned (lcm > N)
≤ 2ⁿ, data-dependent
zero terms have zero supersets
Same-size collapse
O(n)
derangements / surjections only
Brute-force oracle
O(N · n)
scan [1,N], test each
Independent of N?
yes
cost depends on n, not N
cheap / sub-exponential exponential in n
Operation log
How to read this animation
Step applies one PIE term; Run auto-plays at the chosen speed; Reset rebuilds from your inputs.
N is the range upper bound; numbers is the comma-separated list whose multiples you are counting (first three drive the Venn labels A, B, C).
Union mode enumerates non-empty subsets (mask 1 … 2ⁿ−1); Complement mode also includes mask 0 (the universe term, +N).
Each subset's intersection size is floor(N / lcm(chosen numbers)) — the count of integers in [1,N] divisible by all chosen numbers.
Odd-size subsets are added, even-size subtracted; once lcm > N the term is 0 and contributes nothing (a free prune).
Set the numbers to the distinct primes of N (e.g. N=30, numbers=2,3,5) and the complement total equals Euler's totient φ(N).
Self-contained visualization (no external resources). Both panels compute the identical alternating sum
Σ∅≠S (−1)|S|+1 |⋂ Aᵢ|. The sign is driven solely by popcount(mask).
See middle.md for the coprime/divisible-by derivations, senior.md for pruning and scale, and
professional.md for the proofs and the Möbius generalization.