解题思路:
参考了一下别的同学的代码,发现单开一个数组的容易在位数判断上面出问题,开双数组比较保险,同时,short以10进位不可取(爆内存),int也是,long long的化开高位可以达到效果,然而开了的话就需要一些固定输出位的操作,否则会少0.
参考代码:
#include<bits/stdc++.h> #define hh ios::sync_with_stdio(false),cin.tie(0); using namespace std; typedef unsigned long long ull; const int maxn=1e6+5; const ull Yasuo=10000000000000000; const int bit=16; ull a[maxn],b[maxn]; ull n,pos=0; int main() { hh; cin>>n; a[0]=1; for(int i=1; i<=n; i++) { memset(b,0,sizeof(b)); for(int j=0; j<=pos; j++) { b[j]+=a[j]*i; if(b[j]>=Yasuo) { pos++; } b[j+1]=b[j]/Yasuo; b[j]%=Yasuo; } while(!b[pos]) pos--; for(int j=0; j<=pos; j++) { a[j]=b[j]; } } for (int j = pos; j >= 0; j--) { if (j == pos) cout << a[j]; else cout << setw(bit) << setfill('0') << a[j]; } cout<<endl; return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:784 |
C语言考试练习题_排列 (C语言代码)浏览:1326 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:541 |
【蟠桃记】 (C语言代码)浏览:651 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:642 |
校门外的树 (C语言代码)浏览:961 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:524 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:644 |
淘淘的名单 (C语言代码)浏览:1104 |
用筛法求之N内的素数。 (C语言代码)浏览:664 |