hdu 1042 N!(大数的阶乘)

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 55659    Accepted Submission(s):
15822

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
1
2
3
 
Sample Output
1 2 6
 
这个题目就是一个大数的乘法,不难,但是半年前的我写这个题目的时候写了很长很长的代码 麻烦的很 花了很久才过的  ,现在想起来就重新写了一遍 代码精简了好多,而且也美观了很多 ,哈哈 事实证明我这半年还是有进步的  O(∩_∩)O!
 
 #include<iostream>
#include<cstdio>
#include<cstring> using namespace std; #define ll long long int num[]; int main()
{
int n;
while(~scanf("%d",&n))
{
memset(num,,sizeof(num));
num[]=;
int pre=;
int len=;
for(int i=;i<=n;i++)
{
pre=;
for(int j=;j<len;j++)
{
num[j]=num[j]*i+pre/;
pre=num[j];
num[j]%=;
}
while(pre>)
{
num[len]=pre/%;
len++;
pre/=;
}
}
for(int i=len-;i>=;i--)
printf("%d",num[i]);
printf("\n");
}
return ;
}
上一篇:wpa_cli 连接 wifi


下一篇:js弹出对话框的方法总结