Coprime to N in a Range — Solution & Editorial
Factor N to its distinct primes, then inclusion–exclusion: count multiples of each squarefree product of primes, alternating signs. Use prefix difference over the range.
Complexity: O(2ω(N))
Factor N to its distinct primes, then inclusion–exclusion: count multiples of each squarefree product of primes, alternating signs. Use prefix difference over the range.
Complexity: O(2ω(N))