Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
82337 sh25_shenpy 高精度阶乘的和 C++ 解答错误 0 MS 264 KB 2676 2026-01-11 17:42:45

Tests(0/4):


#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N = 1010 ; struct BIG { int a[N] ; void set(string s) { a[0] = s.size() ; s = " " + s ; for(int i = 1 ; i <= a[0] ; i++ ) a[i] = s[a[0] - i + 1] - '0' ; } void read() { string s ; cin >> s ; a[0] = s.size() ; s = " " + s ; for(int i = 1 ; i <= a[0] ; i++ ) a[i] = s[a[0] - i + 1] - '0' ; } void print() { for(int i = 1 ; i <= a[0] ; i++ ) cout << a[a[0] - i + 1]; cout << endl ; } }; BIG operator + (const BIG &x , const BIG &y ); BIG operator - (const BIG &x , const BIG &y ); BIG operator * (const BIG &x , const int &y ); BIG operator / (const BIG &x , const int &y ); bool operator< (const BIG &x , const BIG &y ); BIG fac (int x ) ; int main() { BIG ans ; int n ; cin >> n ; for(int i = 1 ; i <= n ; i++ ) { BIG tmp = fac(i) ; ans = ans + tmp ; } ans.print() ; return 0; } BIG operator + (const BIG &x , const BIG &y ) { BIG z ; z.a[0] = max(x.a[0] , y.a[0] ) ; int u = 0 ; for(int i = 1 ; i <= z.a[0] ; i++ ) { int t = u ; if(x.a[0] >= i) t += x.a[i] ; if(y.a[0] >= i) t += y.a[i] ; u = t / 10 ; z.a[i] = t % 10 ; } if(u > 0) z.a[0]++ , z.a[z.a[0]] = u ; return z ; } BIG operator - (const BIG &x , const BIG &y ) { BIG z ; z.a[0] = max(x.a[0] , y.a[0]) ; for(int i = 1 ; i <= z.a[0] ; i++ ) z.a[i] = x.a[i] - y.a[i] ; for(int i = 1 ; i <= z.a[0] ; i++ ) if(z.a[i] < 0) { z.a[i] += 10 ; z.a[i + 1]-- ; } while(z.a[z.a[0]] == 0 && z.a[0] > 1) z.a[0]-- ; return z ; } bool operator < (const BIG &x , const BIG &y ) { if(x.a[0] != y.a[0]) return x.a[0] < y.a[0] ; for(int i = x.a[0] ; i >= 1 ; i-- ) if(x.a[i] != y.a[i]) return x.a[i] < y.a[i] ; return false ; } BIG operator * (const BIG &x , const int &y ) { BIG z ; z.a[0] = x.a[0] ; for(int i = 1 ; i <= z.a[0] ; i++ ) z.a[i] = x.a[i] * y ; for(int i = 1 ; i <= z.a[0] ; i++ ) { z.a[i + 1] += z.a[i] / 10 ; z.a[i] %= 10 ; } while(z.a[z.a[0] + 1] > 0) { z.a[0]++ ; z.a[z.a[0] + 1] += z.a[z.a[0]] / 10 ; z.a[z.a[0]] %= 10 ; } return z ; } BIG operator / (const BIG &x , const int &y ) { BIG z ; z.a[0] = x.a[0] ; int r = 0 ; for(int i = z.a[0] ; i >= 1 ; i-- ) { z.a[i] = (r * 10 + x.a[i]) / y ; r = (r * 10 + x.a[i]) % y ; } while(z.a[z.a[0]] == 0 && z.a[0] > 1) z.a[0]-- ; return z ; } BIG fac (int x ) { BIG z ; z.set("1") ; for(int i = 1 ; i <= x ; i++ ) { z = z * i ; } return z ; }


测评信息: