51NOD N!

#include<iostream>
#include<string.h>
#define MAX 40000
using namespace std;


int main()
{
    int n;
int i,j;
    int a[MAX];      //存数运算结果
int p,h,temp;          //p存储当前结果的位数,h为进位
memset(a,0,sizeof(a));
a[0]=1;
p=1;
cin>>n;
for(i=2;i<=n;i++)   //循环与2,3,4.....n相乘
{
 
for(j=1,h=0;j<=p;++j)    //让a[]的每位与i相乘
{
temp=a[j-1]*i+h;
h=temp/10;//进位
a[j-1]=temp%10;//余数存入a[j]
}
while(h>0)         //如果h不为0,需要进一位(h不可能大于10)
{
a[++p-1]=h%10;
h=h/10;
}
}
for(i=p-1;i>=0;--i)//反输出
{
cout<<a[i];
}
cout<<"\n";
 

}



#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include<stdio.h>
#include<math.h>
using namespace std;
#define ll long long
#define N 1000005
#define mod 100000000000000
ll ans[10000000];
int main()
{
    ll n;
    scanf("%I64d",&n);
        ll i,j;
        ll l=0;
        ans[0]=1;
        for(i=1; i<=n; i+=1)
        {
            ll c=0;
            for(j=0; j<=l; j+=1)
            {
                ll t=ans[j]*i+c;
                ans[j]=t%mod;
                c=t/mod;
            }
            if(c!=0)
            {
                ans[++l]=c;
            }
        }
        printf("%I64d",ans[l]);
        for(i=l-1; i>=0; i-=1)
        {
            printf("%0.14I64d",ans[i]);
        }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值