51nod 1057 N的阶乘 (大数运算)

输入N求N的阶乘的准确值。
 
Input
输入N(1 <= N <= 10000)
Output
输出N的阶乘
Input示例
5
Output示例
120

压位: 每个数组元素存多位数字
 1 #include <cstdio>
 2 #include <string>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <cmath>
 7 using namespace std;
 8 #define pi 3.1415926
 9 #define e 2.718281828459
10 #define ll long long 
11 const int mod=1e8;
12 const int N=10000;
13 int main()
14 {
15     int n,i,j,m;
16     ll a[N]={1},c;
17     scanf("%d",&n);
18     m=0;
19     for(i=1;i<=n;i++){
20         c=0;
21         for(j=0;j<=m;j++){
22             a[j]=a[j]*i+c;
23             c=a[j]/mod;
24             a[j]%=mod;
25         }
26         if(c>0){
27             m++;
28             a[m]=c;
29         }
30     }
31     printf("%lld",a[m]);
32     for(i=m-1;i>=0;i--)
33         printf("%08lld",a[i]);
34     printf("\n");
35     return 0;
36 }

转载于:https://www.cnblogs.com/shixinzei/p/7380311.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值