N!again

来源:互联网 发布:快盘关闭数据如何找回 编辑:程序博客网 时间:2024/06/06 11:04

F - N!Again
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 2674

Description

WhereIsHeroFrom:             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)!

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

Sample Output

24120

找规律,2009=41*7*7
比41大的取模为0

#include <iostream>#include <cstdio>int app(int  t){int sum=1;while(t) {sum=sum%2009;sum=sum%2009*t; sum=sum%2009;t--; }return sum; } int main(){int n;while(~scanf("%d",&n)){   if(n<41)  printf("%d\n",app(n));elseprintf("0\n");}return 0; } 



原创粉丝点击