Data Structures & AlgorithmsHardICPC regional · sieve

Problem: What is the complexity of computing the Euler totient for all numbers up to n with a linear sieve?

  1. A. O(n^2)
  2. B. O(n log n)
  3. C. O(n)
  4. D. O(n sqrt n)

Correct answer: C. O(n)

The linear sieve marks each composite exactly once using its smallest prime factor, giving O(n).

More Coding Interview Problems questions

Exams that ask this topic