#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; #define int long long inline int read() { int ans = 0,op = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') op = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (ans *= 10) += ch - '0'; ch = getchar(); } return ans * op; } #define E 10050 struct bign { int len,v[E]; bign operator + (const bign& b) const { bign c; c.len = max(len,b.len); for(int i = 0;i <= c.len + 2;i++) c.v[i] = 0; for(int i = 0;i < c.len;i++) c.v[i] = v[i] + b.v[i]; for(int i = 0;i < c.len;i++) c.v[i + 1] += c.v[i] / 10,c.v[i] %= 10; if(c.v[c.len]) c.len++; return c; } bign operator * (const bign& b) const { bign c; c.len = len + b.len + 1; for(int i = 0;i <= c.len + 2;i++) c.v[i] = 0; for(int i = 0;i < len;i++) for(int j = 0;j < b.len;j++) { c.v[i + j] += v[i] * b.v[j]; c.v[i + j + 1] += c.v[i + j] / 10,c.v[i + j] %= 10; } while(c.v[c.len] == 0) c.len--; c.len++; return c; } bool operator < (const bign& b) const { if(len > b.len) return 0; if(len < b.len) return 1; for(int i = len - 1;i >= 0;i--) { if(v[i] > b.v[i]) return 0; if(v[i] < b.v[i]) return 1; } } bool operator > (const bign &b) const { if(len > b.len) return 1; if(len < b.len) return 0; for(int i = len - 1;i >= 0;i--) { //printf("%lld %lld %lld ",i,v[i],b.v[i]); if(v[i] > b.v[i]) return 1; if(v[i] < b.v[i]) return 0; } return 0; } bool operator <= (const bign& b) const { return !(*this > b); } bool operator >= (const bign& b) const { return !(*this < b); } bool operator == (const bign& b) const { return *this <= b && b <= *this; } bign operator = (char* s) { len = strlen(s); memset(v,0,sizeof(v)); for(int i = 0;i < len;i++) v[i] = s[len - i - 1] - '0'; return *this; } bign operator = (int x) { char s[E]; sprintf(s,"%lld",x); *this = s; return *this; } bign operator += (const bign& b) { return *this = *this + b; } bign operator / (int x) { bign c; c.len = len; int res = 0; for(int i = len - 1;i >= 0;i--) { res = res * 10 + v[i]; c.v[i] = res / x; res %= x; } while(!c.v[c.len - 1] && c.len > 0) c.len--; return c; } }; inline void print(bign a) { for(int i = a.len - 1;i >= 0;i--) printf("%lld",a.v[i]); //cout << endl; printf(" " ); } main() { return 0; }