/*
* hdu-1042 n!
* mike-w
* 2012-5-21
* big number multiplies small number
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_NUM_LEN 100000
#define WIDTH 4
#define BASE 10000
int mul1(int *s, int e)
{
int end=s[0];
int carry=0,i;
for(i=MAX_NUM_LEN-1;i>=end;i--)
{
s[i]=s[i]*e+carry;
carry=s[i]/BASE;
s[i]%=BASE;
}
while(carry)
{
s[i]=carry;
carry=s[i]/BASE;
s[i]%=BASE;
i--;
}
s[0]=i;
return 0;
}
int disp(int *s)
{
int i=s[0];
while(i<MAX_NUM_LEN && s[i]==0)
i++;
if(i==MAX_NUM_LEN)
putchar('0');
else
printf("%d",s[i]);
for(i++;i<MAX_NUM_LEN;i++)
printf("%0*d",WIDTH,s[i]);
return 0;
}
int main(void)
{
int n,i;
int s[MAX_NUM_LEN];
while(scanf("%d",&n)!=EOF)
{
memset(s,0,sizeof(int)*MAX_NUM_LEN);
s[0]=MAX_NUM_LEN-1;
s[MAX_NUM_LEN-1]=1;
for(i=1;i<=n;i++)
mul1(s,i);
disp(s);
putchar('\n');
}
return 0;
}
/*
* extra words;
* 加上了近似的起始位s[0]后,速度比以前快了不少!
* 在学习中不断进步。
*/
HDU-1042 高精度
最新推荐文章于 2020-12-20 23:08:35 发布