地址:
题意:求n!,注意:0 <= n <= 10000,n = 10000时,长度为35660位。
mark:用数组的方式存放。
代码:
#include#define MOD 10000int a[10010];int main(){ int n,f,s; int i,j; while(~scanf("%d", &n)) { if(n < 2) {printf("1\n");continue;} a[0] = 1; for(i = 2, f = 1, s = 0; i <= n; i++) { for(j = 0; j < f; j++) { s += a[j]*i; a[j] = s%MOD; if(s >= MOD) s /= MOD; else s = 0; } while(s) { a[f++] = s%MOD; s /= MOD; } } for(i = f-1; i >= 0; i--) if(i == f-1) printf("%d", a[i]); else printf("%04d", a[i]); printf("\n"); } return 0;}