hdu 2674 N!Again 数论水题啊~~~
来源:互联网 发布:石鑫网络信息有限公司 编辑:程序博客网 时间:2024/06/01 12:24
N!Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3803 Accepted Submission(s): 2036
Problem 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)!
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以后全是0。。。至少我第一次A的代码就是这个思路。2009以前的打表~~
其次,2009=41*7*7。所以40以后全都是0了。至于40以前的也是打表呗~
附上我的代码:
#include <stdio.h>#define MAX 2009int ans[MAX] ;int main(){int n ;ans[0] = 1 ;for(int i = 1 ; i < MAX ; ++i ){ans[i] = (ans[i-1]*i)%MAX ;}while(~scanf("%d",&n)){if(n>=2009){puts("0") ;}else{printf("%d\n",ans[n]) ;}}return 0;}
与君共勉
0 0
- hdu 2674 N!Again 数论水题啊~~~
- HDU 2674 N!Again(数论)
- ACM HDU 2674 N! Again(数论)
- HDU 2674 N!Again (数论-水题)
- HDU 2674 N!Again (数论-其他)
- HDU 2674 N!Again (数论)
- hdu 2674 N!Again(数论,水题)
- (step7.2.4)hdu 2674(N!Again——简单数论)
- HDOJ 2674-N!Again【数论】
- HDOJ 2674-N!Again【数论】
- HDU 2674 N! Again
- HDU 2674 N! Again
- hdu 2674 N!Again
- HDU 2674 N!Again
- HDU--2674 N!Again
- hdu-2674-N!Again
- hdu 2674 N!Again
- hdu 2674 N!Again
- 基础算法
- 检测字符串长度
- C++面试题_不断更新
- struts2文件上传
- CString与Char*的转换,以及中文字符写入文件,文件的读写等
- hdu 2674 N!Again 数论水题啊~~~
- 【c++ primer读书笔记】【第2章】变量和基本类型
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
- 关于android 如何安装 assets文件下的apk
- Python Paramiko模块安装和使用
- struts工作原理(一个url调用到返回结果全过程)
- VC++ D2D呈现水晶报表并实时刷新
- 腾讯科技讯 在智能手机市场的领先优势缩小后
- Swift - 搜索条(UISearchBar)的用法