N!
log10(10000!) = ∑log10(i)( 1<= i <= 10000) = 35659.5,所以10000!≈10^35659.5,这个数很大,所以用模拟手算乘法的方法计算。
#include<iostream> #include<math.h> using namespace std; #define MAXN 40000 int a[MAXN], bit; void mul(int*m, int a) // m = m * a { int c, i; bit += int(log10(double(a))) + 2; for(c=0,i=0; i<=bit; i++) { c = m[i] * a + c; m[i] = c % 10; c /= 10; } while(m[bit]==0) bit--; } void n_print(int*m) // print { while(bit>=0) cout << m[bit--]; cout << endl; } int main(void) { int n, i; while(cin >> n) { memset(a, 0, sizeof(a)); for(a[0]=1,bit=0,i=1; i<=n; i++) mul(a, i); n_print(a); } return 0; }