Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

What is the sum of gcd(i, 12) over i = 1 to 12?

  1. A. 43
  2. B. 40
  3. C. 36
  4. D. 80

Correct answer: B. 40

Pillai's function is multiplicative: sum of gcd(i, n) over i = 1..n equals the sum over divisors d of n of d times phi(n/d). Computing it directly is fine at n = 12.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic