N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 56210 Accepted Submission(s): 15949
1 2 3
1 2 6
--------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define M 100000
int a[M],i,k,n;
int j,counts;
void init()
{
for(i=1;i<M;i++)
a[i] = 0;
}
int main()
{
init();
while(scanf("%d",&n)!=EOF)
{
a[0]=1; counts = 1;
for(i=1;i<=n;i++)
{
k = 0;
for(j=0;j<counts;j++)
{
int temp;
temp = a[j]*i+k;
a[j] = temp%10;
k = temp/10;
}
while(k)
{
a[counts++] = k%10;
k=k/10;
}
}
// 没有一下2行代码也可以AC
// for(j=M-1;j>=0;j--)
// if(a[j]==0) break;
for(i=counts-1;i>=0;i--)
printf("%d",a[i]);
printf("\n");
init();
}
return 0;
}
-------------------------------------------------
#include<iostream>
#define MAX 100000
using namespace std;
int main()
{
int n,a[MAX];
int i,j,k,count,temp;
while(cin>>n)
{
a[0]=1;
count=1;
for(i=1;i<=n;i++)
{
k=0;
for(j=0;j<count;j++)
{
temp=a[j]*i+k;
a[j]=temp%10;
k=temp/10;
}
while(k)//记录进位
{
a[count++]=k%10;
k/=10;
}
}
for(j=MAX-1;j>=0;j--)
if(a[j])
break;//忽略前导0
for(i=count-1;i>=0;i--)
cout<<a[i];
cout<<endl;
}
return 0;
}