加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

大数阶乘

发布时间:2020-12-14 02:53:12 所属栏目:大数据 来源:网络整理
导读:大数阶乘 时间限制: 3000 ?ms ?|? 内存限制: 65535 ?KB 难度: 3 描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它? 输入 输入一个整数m(0m=5000) 输出 输出m的阶乘,并在输出结束之后输入一个换行符 样例输入

大数阶乘

时间限制: 3000?ms ?|? 内存限制: 65535?KB
难度: 3
描述
我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
输入
输入一个整数m(0<m<=5000)
输出
输出m的阶乘,并在输出结束之后输入一个换行符
样例输入
50
样例输出
30414093201713378043612608166064768844377641568960512000000000000
代码如下
#include <iostream>
#define N 200000
using namespace std;
int number[N];
void creat()
{
? ? number[0] = 1;
? ? for(int i = 1; i < N; i ++)
? ? ? ? number[i] = 0;


}
int m(int n)
{
? ? creat();
? ? int result_size = 1;
? ? int carryBit = 0;
? ? if(n == 1)
? ? ? ? return result_size;
? ? for(int i = 2; i <= n; i ++)
? ? {
? ? ? ? for(int j = 0; j < result_size; j ++)
? ? ? ? {
? ? ? ? ? ? int temp = number[j] * i + carryBit;
? ? ? ? ? ? number[j] = temp % 10;
? ? ? ? ? ? carryBit = temp / 10;
? ? ? ? }
? ? ? ? while(carryBit != 0)
? ? ? ? {
? ? ? ? ? ? number[result_size] = carryBit % 10;
? ? ? ? ? ? result_size ++;
? ? ? ? ? ? carryBit = carryBit / 10;
? ? ? ? }
? ? }
? ? return result_size;
}
void print()
{
? ? int n;
? ? cin >> n;
? ? int t = m(n);
? ? for(int i = t - 1; i >= 0; i --)
? ? ? ? cout << number[i];
? ? cout << endl;
}
int main()
{
? ? print();
? ? return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读