admin 管理员组

文章数量: 887031

N!

.php?pid=1042

题意:给定整数 N (0 ≤ N ≤ 10000),你的任务是计算 N! 。

思路:一位一位的进行计算进位;

#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=2e5+9;
const int mod=1e8+7;template <class T>
inline void sc(T &ret)
{char c;ret = 0;while ((c = getchar()) < '0' || c > '9');while (c >= '0' && c <= '9'){ret = ret * 10 + (c - '0'), c = getchar();}
}int a[maxn];
int p;
int main()
{FASTIO;#define endl '\n'int n;while(cin>>n){mem(a,0);a[0]=1;p=1;for(int i=2;i<=n;i++){int jin=0;for(int j=0;j<p;j++){int num=a[j]*i+jin;jin=num/10;a[j]=num%10;}while(jin){a[p++]=jin%10;jin/=10;}}for(int i=p-1;i>=0;i--){cout<<a[i];}cout<<endl;}return 0;
}

 

本文标签: N