Extend factorization carefully
Recognize segmented sieves, factorial exponents, and square completion.
Understand the idea
A segmented sieve marks [L,R] using all base primes through √R. For prime p, start at max(p², ceil(L/p) × p). The exponent of p in n! is floor(n/p) + floor(n/p²) + ... .
Trace a small example
The exponent of 2 in 10! is 5 + 2 + 1 = 8. To make n a square with the smallest positive multiplier, include each prime with odd exponent once. For 72 = 2³ × 3², multiply by 2 to obtain 144.
Conditions and cost
Mark 0 and 1 nonprime when a segment includes them. Base primes must cover √R. Repeatedly divide n by p when counting factorial exponents to avoid overflowing powers. The reference also introduces a linear SPF sieve.
What is the smallest positive m making 45m a square?
Turn the idea into code
Find the number of trailing zeros of 100!.
Give me a hint
Count factors of 5; there are more factors of 2.
Show the explained solution
floor(100/5) + floor(100/25) = 20 + 4 = 24, so there are 24 trailing zeros.
Your notes
Mark complete when you can explain it yourself.