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?
- A. O(n^2)
- B. O(n log n)
- C. O(n)
- 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
- Problem: Which technique computes the sum of a function over all subsets of a set of size n in O(n 2^n)?
- Problem: What does the cross product of two 2D vectors (a, b) and (c, d) equal?
- Problem: Which approach finds the k-th lexicographically smallest substring of a string?
- Problem: What is the expected number of distinct values when n balls are thrown uniformly into n bins?
- Problem: Which algorithm is the standard way to find the minimum number of swaps to sort a permutation?
- Problem: What is the complexity of binary exponentiation for computing a^b mod m?