hdu1042 N!(高精度水过)

来源:互联网 发布:手机网络ip地址查询 编辑:程序博客网 时间:2024/05/17 22:38

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 76906    Accepted Submission(s): 22482


Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
 

Input
One N in one line, process to the end of file.
 

Output
For each N, output N! in one line.
 

Sample Input
123
 

Sample Output
126

熟悉了下高精度模板,水过。
但我是数组每一位存一个数,每个位置存4位还不太熟练= =
高精度水过代码:
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<string>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define eps 1e-8#define zero(x) (((x>0?(x):-(x))-eps)#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define ull unsigned long long#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfd(a) scanf("%lf",&a)#define sfd2(a,b) scanf("%lf%lf",&a,&b)#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)#define sfc(a) scanf("%c",&a)#define ull unsigned long long#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 2<<20;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;#define MAX 50010int num[MAX];int main(){    //freopen("data.in","r",stdin);    int n;    while(~sf(n))    {        mem(num,0);        num[0]=1,num[1]=1;        for(int i=1;i<=n;i++)        {            int len=num[0];            for(int j=1;j<=len;j++)                num[j]*=i;            for(int j=1;j<=num[0];j++)            {                if(num[j]>=10)                {                    num[j+1]+=num[j]/10;                    num[j]%=10;                }                if(num[num[0]+1])                    num[0]++;            }        }        for(int i=num[0];i>=1;i--)            printf("%d",num[i]);        pfn;    }    return 0;}

0 0
原创粉丝点击