N!(1042)hdu(大数阶乘)
N!Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 56210 Accepted Submission(s): 15949
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
Sample Output
-------------------------------------------------------------- #include <stdio.h> ------------------------------------------------- #include<iostream> #define MAX 100000 using namespace std; int main() { ? ? int n,a[MAX]; ? ? int i,j,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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |