Data Structures & AlgorithmsVery hardICPC regional · GATE CS

Problem: Compute Euler's totient φ(n) summed over n = 1 to 30 (φ(n) counts integers in [1, n] coprime to n, with φ(1) = 1).

  1. A. 277
  2. B. 270
  3. C. 435
  4. D. 278

Correct answer: D. 278

Adding φ(1) = 1, φ(2) = 1, …, φ(30) = 8 gives 278. Using φ(1) = 0 gives 277, stopping at 29 drops φ(30) = 8 (270), and treating every n as prime (φ(n) = n − 1) gives 435.

More Coding Interview Problems questions

Exams that ask this topic