N! Again
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 3481 accepted submission (s): 1889
Problem descriptionWhereisherofrom: zty, what are you doing?
Zty: I want to calculate n !......
Whereisherofrom: so easy! How big N is?
Zty: 1 <= n <= 1000000000000000000000000000000000000000000000...
Whereisherofrom: Oh! You must be crazy! Are you fa Shao?
Zty: No. I Haven's finished my saying. I just said I want to calculate n! MoD 2009
Hint: 0! = 1, n! = N * (N-1 )!
InputEach line will contain one integer N (0 <= n <= 10 ^ 9). process to end of file.
OutputFor each case, output n! MoD 2009
Sample Input4 5
Sample output24120 question Source: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2674
1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int n; 6 int ans,i; 7 while(~scanf("%d",&n)) 8 { 9 ans=1;10 if(n>=2009)11 printf("0\n");12 else13 {14 for(i=1;i<=n;i++) 15 {16 ans*=i;17 ans%=2009;18 }19 printf("%d\n",ans); 20 }21 }22 return 0;23 }