N!
Time Limit: 10000/5000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 55971 accepted submission (s): 15886
Problem descriptiongiven an integer N (0 ≤ n ≤ 10000), your task is to calculate n!
Inputone N in one line, process to the end of file.
Outputfor each n, output n! In one line.
Sample Input
123
Sample output
126# Include <stdio. h> int main () {int I, j, n, m; while (scanf ("% d", & N )! = EOF) {If (n <0) {continue;} int STR [10000] = {0}; STR [0] = 1; M = 0; for (I = 1; I <= N; I ++) // m is used to control carry. For (j = 0; j <= m; j ++) {STR [J] = STR [J] * I; if (j> 0 & STR [J-1]> = 10000) {STR [J] = STR [J] + STR [J-1]/10000; STR [J-1] = STR [J-1] % 10000;} If (STR [m]> = 10000) m ++;} printf ("% d ", STR [m]); for (I = m-1; I> = 0; I --) printf ("% 04d", STR [I]); printf ("\ n");} return 0 ;}
N! (Hangdian 1042)