51nod1057 N的阶乘
2016-07-13 23:16
176 查看
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1057
题意:中文题。
分析:裸的高精度会T,压压位就过了。
代码(压4位):
#include<map> #include<set> #include<cmath> #include<queue> #include<bitset> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<cstring> #include<iostream> #include<algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=50005; const int mod=100000000; const int MOD1=1000000007; const int MOD2=1000000009; const double EPS=0.00000001; typedef long long ll; const ll MOD=998244353; const int INF=1000000010; const ll MAX=1000000000000; const double pi=acos(-1.0); typedef double db; typedef unsigned long long ull; int a ; int main() { int i,j,n; scanf("%d", &n); a[0]=a[1]=1; for (i=2;i<=n;i++) { for (j=1;j<=a[0];j++) a[j]*=i; for (j=1;j<a[0];j++) a[j+1]+=a[j]/10000,a[j]%=10000; while (a[a[0]]>9999) { a[a[0]+1]+=a[a[0]]/10000; a[a[0]]%=10000;a[0]++; } } printf("%d", a[a[0]]); for (i=a[0]-1;i;i--) if (a[i]<10) printf("000%d", a[i]); else if (a[i]<100) printf("00%d", a[i]); else if (a[i]<1000) printf("0%d", a[i]); else printf("%d", a[i]); printf("\n"); return 0; <h3>} </h3>
代码(压8位):
#include<map> #include<set> #include<cmath> #include<queue> #include<bitset> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<cstring> #include<iostream> #include<algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=50005; const int mod=100000000; const int MOD1=1000000007; const int MOD2=1000000009; const double EPS=0.00000001; typedef long long ll; const ll MOD=998244353; const int INF=1000000010; const ll MAX=1000000000000; const double pi=acos(-1.0); typedef double db; typedef unsigned long long ull; ll a ; int main() { int j,n; scanf("%d", &n); a[0]=a[1]=1ll; for (ll i=2;i<=n;i++) { for (j=1;j<=a[0];j++) a[j]*=i; for (j=1;j<a[0];j++) a[j+1]+=a[j]/100000000ll,a[j]%=100000000ll; while (a[a[0]]>99999999ll) { a[a[0]+1]+=a[a[0]]/100000000ll; a[a[0]]%=100000000ll;a[0]++; } } printf("%d", a[a[0]]); for (j=a[0]-1;j;j--) if (a[j]<10ll) printf("0000000%I64d", a[j]); else if (a[j]<100ll) printf("000000%I64d", a[j]); else if (a[j]<1000ll) printf("00000%I64d", a[j]); else if (a[j]<10000ll) printf("0000%I64d", a[j]); else if (a[j]<100000ll) printf("000%I64d", a[j]); else if (a[j]<1000000ll) printf("00%I64d", a[j]); else if (a[j]<10000000ll) printf("0%I64d", a[j]); else printf("%I64d", a[j]); printf("\n"); return 0; }
相关文章推荐
- 深入理解C++类的构造函数与析构函数
- 程序员的3年之痒改变的不止薪水(二)
- percona-toolkit -1
- 糗事百科笑话
- 最小费最大流,最小权最大匹配,拆点法(最优巴士路线设计 uva 1349)
- Android自学历程—手把手教你使用OkHttp(基础篇)
- 分支记录和性能监视
- navicat提权及星外主机注册表mssql密码位置
- navicat提权及星外主机注册表mssql密码位置
- hihocoder #1196 : 高斯消元·二
- 输入输出组织
- Codeforces 682C. Alyona and the Tree
- 一段机械的平均图像求背景的代码
- 打开大文件的方法
- 李洪强漫谈iOS开发[C语言-010] - C语言简要复习
- 设计模式之单例模式
- 提交时提示ip被记录,防注入系统的利用
- 产品助理day8
- Python 爬虫入门(二)—— IP代理使用
- UItableView动态刷新数据 --------->>>组、行动态加载