N!Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5078 Accepted Submission(s): 2707
Hint : 0! = 1, N! = N*(N-1)!
Input
Each line will contain one integer N(0 <= N<=10^9). Process to end of file.
Output
For each case, output N! mod 2009
Sample Input
4
5
5
Sample Output
24
120
120
水题
思路:将1-2009的阶乘先存在f[2010],之后用a,b来存N/2009和N% 2009的结果,最后结果为ans=f[2009]^a*f[b]%2009.
#include "cstdio" #include "algorithm" #include "cstring" ]; int main() { int n,ans; int a,b; f[]=; ;i<=;i++){ f[i]=f[i-]*i%; } ){ ans=; a=n/; b=n%; ;i<a;i++){ ans=ans*f[]%; } ) {ans=ans*f[b]%;} printf("%d\n",ans); } ; }