51nod 1057 N的阶乘大数-划分

51nod 1057 N的阶乘(大数-划分)

实话说,题目我做过,但是再次写到这道题目的时候,我就不再想起用这样的方法。所以,我认为记录下来是很有必要的,
1.可以强化理解
2.可以回顾

这道题目,用大数乘法做太过繁琐。划分其实是将答案划分成可以输出的数据,再以格式化输出
那么,为什么这题能使用这种方法算大数,原因是虽然乘的数量多,但是其每个乘数不超过10000,
数组记录的每一位于其相乘可以用long long记录,如果以8位一个划分,那么最大也就12位。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define E 2.71828
#define MOD 100000000
#define N 11000

LL a[N];
int main()
{
    int n;
    scanf("%d",&n);
    a[0] = 1;
    int m = 1;

    for(int i = 1; i <= n; i++)
    {
        LL t = 0;//printf("sdfs");
        for(int j = 0; j < m; j++)
        {
            LL x = a[j]*i+t;
            t = x / MOD;
            a[j] = x % MOD;
        }
        if(t > 0)   //jin wei
            a[m++] = t;
    }
    printf("%lld",a[m-1]);
    for(int i = m-2; i >= 0; i--)
        printf("%0.8lld",a[i]);
    printf("\n");
    return 0;
}

相关文章

自1998年我国取消了福利分房的政策后,房地产市场迅速开展蓬...
文章目录获取数据查看数据结构获取数据下载数据可以直接通过...
网上商城系统MySql数据库设计
26个来源的气象数据获取代码
在进入21世纪以来,中国电信业告别了20世纪最后阶段的高速发...