hdu 1042 N! 大数相乘。

N!

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

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
 
#include <iostream> using namespace std; int num[8000]; int main() { int i , j, n, t , carry; while(scanf("%d", &n)!= EOF) { if (n == 0) { printf("1/n"); continue; } memset(num, 0, sizeof(num)); t = 1; num[1] = 1; for (i = 2 ; i <= n; i++) { carry = 0; for (j = 1; j <= t; j++) { num[j] = num[j] * i + carry; carry = num[j] / 100000; num[j] = num[j] % 100000; } while (carry) { t++; num[t] = carry % 100000; carry /= 100000; } } printf("%d", num[t]); for (i = t - 1; i >= 1; i--) { printf("%05d", num[i]); //格式化输出, 补前导0 } printf("/n"); } return 0; }

 

你可能感兴趣的:(Integer,input,each,output)