UVa 160 - Factors and Factorials

Summary
Bruteforce on all primes up to 100.

Explanation
Since the upper limit for N is 100, then the largest prime that can divide N! is 97. This is a rather small number, so we can simply walk the list of primes in any old fashion and see how many times it divides into N!. Since N is so small, it is very hard to have a solution time out.

Gotcha's
N! for N = 100 will not fit into any integral type, you must determine divisibility in another manner. And also be cautious that you are not printing a newline when factors size in 15.

Input
2 5 53 100 0

Output
2! = 1  5! =  3  1  1 53! = 49 23 12  8  4  4  3  2  2  1  1  1  1  1  1        1 100! = 97 48 24 16  9  7  5  5  4  3  3  2  2  2  2        1  1  1  1  1  1  1  1  1  1

Solutions

 * C++: http://acm-solution.blogspot.sg/2010/11/acm-uva-160-factors-and-factorials.html