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).
- A. 277
- B. 270
- C. 435
- 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
- Problem: How many positive divisors does 720 have?
- Problem: Find the modular inverse of 7 modulo 26 (the value x with 0 ≤ x < 26 such that 7x ≡ 1 mod 26).
- Problem: A Gray code of 4 bits is generated as g = n XOR (n >> 1) for n = 0 to 15. What is the Gray code value of n = 11?
- Problem: The sum of the digits of 2^100 written in base 10 is computed. What is that sum?
- Problem: In a spiral traversal of a 5×5 matrix filled row-wise with 1 to 25, the traversal starts at the top-left and goes right, then…
- Problem: A bitmask DP problem: count the subsets of {1, 2, ..., 10} whose sum is a multiple of 5 (the empty set counts, since its sum 0 is…