标签:限制 out c++ item ref line hid ems main
输入N(1 <= N <= 10000)
输出N的阶乘
5
120
#include <bits/stdc++.h> #define clear(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int mod = 1e8; ll s[10010]; int main () { int n; while (~scanf("%d",&n) ) { clear(s); int m =0; s[0] = 1; for(int i=1;i <= n;i++) { int c = 0;//c表示最高位所留下的 相当于模拟乘法把 for(int j=0;j <= m;j++) { s[j] = s[j]*i + c; c = s[j] /mod; s[j] %= mod; } if(c > 0) { m++; s[m] = c; } } printf("%lld",s[m]); for(int i=m-1;i >= 0;i--) printf("%08lld",s[i]); puts(""); } return 0; }
标签:限制 out c++ item ref line hid ems main
原文地址:http://www.cnblogs.com/Draymonder/p/7295053.html