题目链接:51nod 1057 N的阶乘
1 #include<cstdio> 2 using namespace std; 3 typedef long long ll; 4 const int N = 10000; 5 const int mod = 1e8; 6 ll a[N] = {1}; 7 int n; 8 int main(){ 9 int i, j, c, cnt; 10 scanf("%d", &n); 11 cnt = 1; 12 for(j = 2; j <= n; ++j){ 13 for(c = i = 0; i <cnt; ++i){ 14 a[i] = a[i] * j + c; 15 c = a[i] / mod; 16 a[i] %= mod; 17 } 18 if(c > 0){ 19 a[i] = c; 20 cnt++; 21 } 22 } 23 printf("%lld", a[--cnt]); 24 while(cnt){ 25 printf("%08lld", a[--cnt]); 26 } 27 return 0; 28 }
时间: 2024-10-05 17:05:56