题目链接: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 }
View Code

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-07-24
  • 2021-11-17
  • 2021-10-18
  • 2021-08-12
猜你喜欢
  • 2022-12-23
  • 2022-02-14
  • 2022-03-10
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案