Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: What is the number of trailing zeros in 100! expressed in base 6 (count of factors of 6)? Run the code.

Problem: What is the number of trailing zeros in 100! expressed in base 6 (count of factors of 6)? Run the code.
n = 100
c2 = c3 = 0
for x in range(1, n + 1):
    t = x
    while t % 2 == 0:
        c2 += 1
        t //= 2
    t = x
    while t % 3 == 0:
        c3 += 1
        t //= 3
print(min(c2, c3))
What is printed?
  1. A. 48
  2. B. 97
  3. C. 18
  4. D. 16

Correct answer: A. 48

v₂(100!) = 97 and v₃(100!) = 48, and each 6 needs one of each, so min = 48. 97 uses the 2s, while 16 + 2 = 18 counts only multiples of 6 and 36, and 16 counts multiples of 6.

More Coding Interview Problems questions

Exams that ask this topic