اعداد بزرگ
return (b < a || b == a);
} bool operator < (BigInt a, int b) {
return (a < Integer(b));
} bool operator > (BigInt a, int b) {
return (a > Integer(b));
} bool operator == (BigInt a, int b) {
return (a == Integer(b));
} bool operator >= (BigInt a, int b) {
return (a >= Integer(b));
} bool operator ⇐ (BigInt a, int b) {
return (a <= Integer(b));
} BigInt max(BigInt a, BigInt b) {
if (a > b) return a; return b;
} BigInt min(BigInt a, BigInt b) {
if (a < b) return a; return b;
} BigInt operator + (BigInt a, BigInt b) {
Set(a); Set(b); BigInt ans; int carry = 0; FOR(i,0,max(a.size(), b.size())-1) { if (i < a.size()) carry += a[i]; if (i < b.size()) carry += b[i]; ans.pb(carry%base); carry /= base; } if (carry) ans.pb(carry); Set(ans); return ans;
} BigInt operator + (BigInt a, int b) {
return a + Integer(b);
} BigInt operator (BigInt &a) { a a = a + 1; return a; } void operator += (BigInt &a, BigInt b) { a = a + b; } void operator += (BigInt &a, int b) { a = a + b; } BigInt operator - (BigInt a, BigInt b) { Set(a); Set(b); BigInt ans; int carry = 0; FOR(i,0,a.size()-1) { carry += a[i] - (i < b.size() ? b[i] : 0); if (carry < 0) ans.pb(carry+base), carry = -1; else ans.pb(carry), carry = 0; } Set(ans); return ans; } BigInt operator - (BigInt a, int b) { return a - Integer(b); } void operator -- (BigInt &a) { // --a a = a - 1; } void operator -= (BigInt &a, BigInt b) { a = a + b; } void operator -= (BigInt &a, int b) { a = a - b; } BigInt operator * (BigInt a, BigInt b) { Set(a); Set(b); BigInt ans; ans.assign(a.size()+b.size(), 0); FOR(i,0,a.size()-1) { ll carry = 0ll; for (int j=0;j<b.size() ) { ll s = ans[i+j] + carry + (ll)a[i]*(j<b.size()?(ll)b[j]:0ll); ans[i+j] = s%base; carry = s/base; } } Set(ans); return ans; } BigInt operator * (BigInt a, int b) { return a * Integer(b); } void operator *= (BigInt &a, BigInt b) { a = a * b; } void operator *= (BigInt &a, int b) { a = a * b; } BigInt operator / (BigInt a, BigInt b) { Set(a); Set(b); if (b == Integer(0)) return Integer("-1"); BigInt ans, cur; FORD(i,a.size()-1,0) { cur.insert(cur.begin(), a[i]); int x = 0, L = 0, R = base; while (L ⇐ R) { int mid = (L+R)»1; if (b*Integer(mid) > cur) { x = mid; R = mid-1; } else L = mid+1; } cur = cur - Integer(x-1)*b; ans.insert(ans.begin(),x-1); } Set(ans); return ans; } BigInt operator / (BigInt a, int b) { Set(a); BigInt ans; ll cur = 0ll; FORD(i,a.size()-1,0) { cur = (cur*(ll)base + (ll)a[i]); ans.insert(ans.begin(),cur/b); cur %= b; } Set(ans); return ans; } void operator /= (BigInt &a, BigInt b) { a = a / b; } void operator /= (BigInt &a, int b) { a = a / b; } BigInt operator % (BigInt a, BigInt b) { Set(a); Set(b); if (b == Integer(0)) return Integer("-1"); BigInt ans; FORD(i,a.size()-1,0) { ans.insert(ans.begin(), a[i]); int x = 0, L = 0, R = base; while (L ⇐ R) { int mid = (L+R)»1; if (b*Integer(mid) > ans) { x = mid; R = mid-1; } else L = mid+1; } ans = ans - Integer(x-1)*b; } Set(ans); return ans; } int operator % (BigInt a, int b) { Set(a); if (b == 0) return -1; int ans = 0; FORD(i,a.size()-1,0) ans = (ans*(base%b) + a[i]%b)%b; return ans; } void operator %= (BigInt &a, BigInt b) { a = a % b; } void operator %= (BigInt &a, int b) { a = a % Integer(b); } BigInt gcd(BigInt a, BigInt b) { Set(a); Set(b); while (b > Integer(0)) { BigInt r = a%b; a = b; b = r; } Set(a); return a; } BigInt lcm(BigInt a, BigInt b) { return (a*b/gcd(a,b)); } BigInt sqrt(BigInt a) { BigInt x0 = a, x1 = (a+1)/2; while (x1 < x0) { x0 = x1; x1 = (x1+a/x1)/2; } return x0; } BigInt pow(BigInt a, BigInt b) { if (b == Integer(0)) return Integer(1); BigInt tmp = pow(a, b/2); if (b%2 == 0) return tmp * tmp; return tmp * tmp * a; } BigInt pow(BigInt a, int b) { return pow(a,(Integer(b))); } int log(int n, BigInt a) { log_n(a)
Set(a); int ans = 0; while (a > Integer(1)) { ans++; a /= n; } return ans;
}
int main() {
BigInt B; cin >> B; BigInt A = Integer("123456789"); BigInt C = Integer(123456789ll); int x; x = 123456789;
if (B <= A) cout << A - B; else { cout << "-"; cout << B - A; }
cout << A + B; Print(A + x); cout << A * B; Print(A * x); cout << A / B; Print(A / x); cout << A % B; printf("%d\n", A % x);
C = ++A; ++B; C += B + x; Print(A); Print(B); Print(C);
cout << max(A,B); cout << min(A,B);
cout << gcd(A,B); cout << lcm(A,B);
cout << sqrt(A); printf("%d %d %d\n", log(2,A), log(10,B), log(5,C));
A = Integer(16); x = 12; cout << pow(A,B); cout << pow(A,x);
return 0;
} </code>