Test instructions: To find the factorial of a number n, the number of the 1th is not the number of 0.
Train of thought: [1,n] Multiply each, appear suffix 0 to filter out, for example 12300 becomes 123, continue to count down. To solve the problem of long long, the remaining number of mods, filter out the previous too large part, because the calculation is useless. How much should this mod be? 1 billion on the line.
1#include <bits/stdc++.h>2 #defineLL Long Long3 using namespacestd;4 Const intn=10001;5 Const intMod=1000000000;6 intAns[n];7 8 voidInit ()9 {TenLL fun=1; Oneans[1]=1; A for(intI=2; i<n; i++) - { -fun*=i; the while(fun%Ten==0) -Fun/=Ten;//filter out the suffix 0 -ans[i]=fun%Ten;//take the last one . -fun%=MoD; + } - } + A intMain () at { - //freopen ("Input.txt", "R", stdin); - init (); - intA; - while(~SCANF ("%d",&a)) -printf"%5d-%d\n", A,ans[a]); in return 0; -}
AC Code
UVA 568 Just The Facts (factorial)