Data Structures & AlgorithmsVery hardICPC regional · number theory
Problem: What is the sum of Euler's totient phi(k) for k = 1 to 20? Run the code.
Problem: What is the sum of Euler's totient phi(k) for k = 1 to 20? Run the code.
from math import gcd print(sum(sum(1 for g in range(1, k + 1) if gcd(g, k) == 1) for k in range(1, 21)))What is printed?
- A. 128
- B. 110
- C. 120
- D. 100
Correct answer: A. 128
Summing the totient phi(k) for k = 1..20 gives 128, computed exactly by counting coprime residues for each k.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] have exactly 4 positive divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1…
- Problem: What is the maximum number of pairwise non-overlapping non-empty subarrays of [1, -1, 2, -2, 3, -3] each having sum zero? Run the…
- Problem: How many 3-element subsets of {1, 2, 3, 4, 5, 6} have a sum divisible by 3? Run the code. python from itertools import…
- Problem: Minimum number of deletions so that no two adjacent characters of 'aaabbb' are equal. Run the code. python s = 'aaabbb' kept = []…
- Problem: What is the maximum product of positive integer parts when 10 is split into at least two parts? Run the DP. python n = 10 dp =…
- Problem: How many integer partitions does 6 have (unordered sums of positive integers equal to 6)? Run the DP. python n = 6 p = [1] + [0]…