Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C

Problem: The number of trailing zeros of 500! written in base 6 (i.e., how many times 6 divides 500!) is what value?

  1. A. 247
  2. B. 494
  3. C. 98
  4. D. 239

Correct answer: A. 247

6 = 2 × 3, so the exponent of 6 in 500! is min(v₂, v₃) = v₃ = 166 + 55 + 18 + 6 + 2 = 247. Taking v₂ gives 494, applying Legendre's formula to 6 as if it were prime gives 83 + 13 + 2 = 98, and stopping v₃ after the 27-term gives 239.

More Coding Interview Problems questions

Exams that ask this topic