本文共 1169 字,大约阅读时间需要 3 分钟。
#include#include char* myblog[] = { "http://www.cnblogs.com/archimedes/", "hdoj1042", "mail: codingwu@gmail.com"};int a[50000];void count(int n){ int i, flag, digit, j, t; a[0] = 1; digit = 1; j = 1; for(i = 2; i <= n; i++) { flag = 0; for(j = 0; j < digit; j++) { t = a[j] * i + flag; if(t >= 10) { a[j] = t % 10; flag = t / 10; } else { a[j] = t; flag = 0; } } if(flag) { while(flag) { a[j] = flag % 10; flag /= 10; digit++; j++; } } } for(i = j - 1; i >= 0; i--) printf("%d", a[i]); printf("\n"); }void solve(){ int n; while(scanf("%d", &n) != EOF) { if(n == 0) printf("1\n"); else count(n); }}int main(){ solve(); return 0;}