高...高精度!!!
程序员文章站
2022-03-21 21:35:56
STO "ZlycerQan" ......
#include<bits/stdc++.h> #define maxn 501 const int big_b = 10; const int big_l = 1; inline int intcmp_ (int a, int b) { if (a > b) return 1; return a < b ? -1 : 0; } struct int { #define rg register inline int max (int a, int b) { return a > b ? a : b; } inline int min (int a, int b) { return a < b ? a : b; } std :: vector <int> c; int () {} typedef long long ll; int (int x) { for (; x > 0; c.push_back (x % big_b), x /= big_b); } int (ll x) { for (; x > 0; c.push_back (x % big_b), x /= big_b); } inline void crz () { for (; !c.empty () && c.back () == 0; c.pop_back ()); } inline int &operator += (const int &rhs){ c.resize (max (c.size (), rhs.c.size ())); rg int i, t = 0, s; for (i = 0, s = rhs.c.size (); i < s; ++ i) c[i] += rhs.c[i] + t, t = c[i] >= big_b, c[i] -= big_b & (-t); for (i = rhs.c.size (), s = c.size (); t && i < s; ++ i) c[i] += t, t = c[i] >= big_b, c[i] -= big_b & (-t); if (t) c.push_back (t); return *this; } inline int &operator -= (const int &rhs){ c.resize (max (c.size (), rhs.c.size ())); rg int i, t = 0, s; for (i = 0, s = rhs.c.size (); i < s; ++ i) c[i] -= rhs.c[i] + t, t = c[i] < 0, c[i] += big_b & (-t); for (i = rhs.c.size (), s = c.size (); t && i < s; ++ i) c[i] -= t, t = c[i] < 0, c[i] += big_b & (-t); crz (); return *this; } inline int &operator *= (const int &rhs){ rg int na = c.size (), i, j, s, ai; c.resize (na + rhs.c.size ()); ll t; for (i = na - 1; i >= 0; -- i){ ai = c[i], t = 0, c[i] = 0; for (j = 0, s = rhs.c.size (); j < s; ++ j){ t += c[i + j] + (ll) ai * rhs.c[j]; c[i + j] = t % big_b, t /= big_b; } for (j = rhs.c.size (), s = c.size (); t != 0 && i + j < s; ++ j) t += c[i + j], c[i + j] = t % big_b, t /= big_b; assert (t == 0); } crz (); return *this; } inline int &operator /= (const int &rhs) { return *this = div (rhs); } inline int &operator %= (const int &rhs) { return div (rhs), *this; } inline int &shlb (int l = 1){ if (c.empty ()) return *this; c.resize (c.size () + l);rg int i; for (i = c.size () - 1; i >= l; -- i) c[i] = c[i - l]; for (i = 0; i < l; ++ i) c[i] = 0; return *this; } inline int &shrb (int l = 1){ for (rg int i = 0; i < c.size () - l; ++ i) c[i] = c[i + l]; c.resize (max (c.size () - l, 0)); return *this; } inline int div (const int &rhs){ assert (!rhs.c.empty ()); int q, r; rg int i; if (rhs > *this) return 0; q.c.resize (c.size () - rhs.c.size () + 1); rg int _l, _r, mid; for (i = c.size () - 1; i > c.size () - rhs.c.size (); -- i) r.shlb (), r += c[i]; for (i = c.size () - rhs.c.size (); i >= 0; -- i){ r.shlb (); r += c[i]; if (r.comp (rhs) < 0) q.c[i] = 0; else { _l = 0, _r = big_b; for (; _l != _r; ){ mid = _l + _r >> 1; if ((rhs * mid).comp (r) <= 0) _l = mid + 1; else _r = mid; } q.c[i] = _l - 1, r -= rhs * q.c[i]; } } q.crz (), *this = r; return q; } inline int comp (const int &rhs) const { if (c.size () != rhs.c.size ()) return intcmp_ (c.size (), rhs.c.size ()); for (rg int i = c.size () - 1; i >= 0; -- i) if (c[i] != rhs.c[i]) return intcmp_ (c[i], rhs.c[i]); return 0; } friend inline int operator + (const int &lhs, const int &rhs) { int res = lhs; return res += rhs; } inline friend int operator - (const int &lhs, const int &rhs){ if (lhs < rhs){ putchar ('-'); int res = rhs; return res -= lhs; } else { int res = lhs; return res -= rhs; } } friend inline int operator * (const int &lhs, const int &rhs) { int res = lhs; return res *= rhs; } friend inline int operator / (const int &lhs, const int &rhs) { int res = lhs; return res.div (rhs); } friend inline int operator % (const int &lhs, const int &rhs) { int res = lhs; return res.div (rhs), res; } friend inline std :: ostream &operator << (std :: ostream &out, const int &rhs){ if (rhs.c.size () == 0) out << "0"; else { out << rhs.c.back (); for (rg int i = rhs.c.size () - 2; i >= 0; -- i) out << std :: setfill ('0') << std :: setw (big_l) << rhs.c[i]; } return out; } friend inline std :: istream &operator >> (std :: istream &in, int &rhs){ static char s[100000]; in >> s + 1; int len = strlen (s + 1); int v = 0; ll r = 0, p = 1; for (rg int i = len; i >= 1; -- i){ ++ v; r = r + (s[i] - '0') * p, p *= 10; if (v == big_l) rhs.c.push_back (r), r = 0, v = 0, p = 1; } if (v != 0) rhs.c.push_back (r); return in; } friend inline bool operator < (const int &lhs, const int &rhs) { return lhs.comp (rhs) < 0; } friend inline bool operator <= (const int &lhs, const int &rhs) { return lhs.comp (rhs) <= 0; } friend inline bool operator > (const int &lhs, const int &rhs) { return lhs.comp (rhs) > 0; } friend inline bool operator >= (const int &lhs, const int &rhs) { return lhs.comp (rhs) >= 0; } friend inline bool operator == (const int &lhs, const int &rhs) { return lhs.comp (rhs) == 0; } friend inline bool operator != (const int &lhs, const int &rhs) { return lhs.comp (rhs) != 0; } #undef rg }; int main (){ return 0; } int zlycerqan = main (); int main (int argc, char *argv[]) {;}
stozlycerqan