ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
n = 100
z, p = 0, 5
while p <= n:
    z += n // p
    p *= 5
print(z, len(str(__import__('math').factorial(n))) - len(str(__import__('math').factorial(n)).rstrip('0')))
  1. A. 24 24
  2. B. 24 25
  3. C. 25 24
  4. D. 12 24

Correct answer: A. 24 24

Legendre's formula counts trailing zeros of 100! as 100//5 + 100//25 + 100//125 = 24, and the factorial's digit count minus its non-zero digits also gives 24. Both values agree because each trailing zero comes from one factor of 2 and one factor of 5.

More Python Programming questions

Exams that ask this topic