UVa 10220

From Algorithmist
Jump to: navigation, search

10220 - I Love Big Numbers ![edit]

Summary[edit]

This is a simple BigNum problem. You need to know what is factorial!

Explanation[edit]

n!=n\times (n-1)\times (n-2)\times ...\times 2\times 1=1\times 2\times 3\times ...\times m\times ...\times (n-1)\times (n)

Just calculate 1000! (from 1 to 1000) by easy using array product and for every m find sum of the digits of m! and store that in other array. then for ever input data, output from array.

Gotchas[edit]

  • Do not worry about TLE, in fact you just calculate 1000!.

and run time will be about 0.040s

Implementations[edit]

Input[edit]

5
60
100
555
600
789
951
1000

Output[edit]

3
288
648
5193
5715
7965
10035
10539