UVa 10220 【大整数】
可采用uva 623这道题求N!,再最后稍微改一下就好。
参考代码:
1 } 2 #include<cstdio> 3 #include<cstring> 4 #include<iostream> 5 using namespace std; 6 const int maxn = 1005; 7 int f[maxn]; 8 9 int main() 10 { 11 int n; 12 while (cin >> n) 13 { 14 memset(f, 0, sizeof(f)); 15 int len = 1; 16 f[0] = 1; 17 for (int i = 2; i <= n; i++) 18 { 19 int c = 0; 20 for (int j = 0; j < len; j++) 21 { 22 int t = f[j] * i + c; 23 f[j] = t % 1000000; 24 c = t / 1000000; 25 } 26 if (c) f[len++] = c; 27 } 28 int ans = 0; 29 for (int i = len - 1; i >= 0; i--) { 30 while (f[i]) 31 { 32 int t = f[i] % 10; 33 ans += t; 34 f[i] /= 10; 35 } 36 } 37 cout << ans << endl; 38 } 39 return 0; 40 }