高精度阶乘

#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<string> 
#include <math.h>
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll; 
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void out(int n)
{
     if(n > 9)
         out(n / 10);
     putchar(n % 10 + '0');
}
const int INF=0x3f3f3f3f;
const int maxn=1e5+10;
int a[maxn];
int n,t,d;
void inint(){
    n=read();
}
int main(){
    inint();
    a[0]=1;d=1;
    for(int i=2;i<=n;i++){
        int num=0;
        for(int j=0;j<d;j++){
            t=a[j]*i+num;
            a[j]=t%10;
            num=t/10;
        }
        while(num){
            a[d]=num%10;
            num/=10;
            d++;
        }
    }
    printf("%d!=",n);
    for(int i=d-1;i>=0;i--){
        out(a[i]);
    }
} 
原文地址:https://www.cnblogs.com/lipu123/p/12575235.html