Data Structures & AlgorithmsHardICPC regional · number theory

Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code.

Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code.
print(sum(100 // 3 ** k for k in range(1, 6)))
What is printed?
  1. A. 33
  2. B. 36
  3. C. 50
  4. D. 48

Correct answer: D. 48

100 // 3 + 100 // 9 + 100 // 27 + 100 // 81 = 33 + 11 + 3 + 1 = 48. Stopping after the first term gives the trap 33.

More Coding Interview Problems questions

Exams that ask this topic