退役选手ZlycerQan的强大的的高精度
2024-08-30 17:17:23
#include <cstdio>
#include <iostream>
#include <vector>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <cstring> const int Big_B = ;
const int Big_L = ;
inline int intcmp_ (int a, int b) {
if (a > b) return ;
return a < b ? - : ;
}
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 > ; c.push_back (x % Big_B), x /= Big_B);
}
Int (LL x) {
for (; x > ; c.push_back (x % Big_B), x /= Big_B);
}
inline void CrZ () {
for (; !c.empty () && c.back () == ; c.pop_back ());
}
inline Int &operator += (const Int &rhs) {
c.resize (max (c.size (), rhs.c.size ()));
rg int i, t = , S;
for (i = , 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 = , S;
for (i = , S = rhs.c.size (); i < S; ++ i)
c[i] -= rhs.c[i] + t, t = c[i] < , c[i] += Big_B & (-t);
for (i = rhs.c.size (), S = c.size (); t && i < S; ++ i)
c[i] -= t, t = c[i] < , 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 - ; i >= ; -- i) {
ai = c[i], t = , c[i] = ;
for (j = , 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 != && i + j < S; ++ j)
t += c[i + j], c[i + j] = t % Big_B, t /= Big_B;
assert (t == );
}
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 = ) {
if (c.empty ()) return *this;
c.resize (c.size () + l);
rg int i;
for (i = c.size () - ; i >= l; -- i) c[i] = c[i - l];
for (i = ; i < l; ++ i) c[i] = ;
return *this;
}
inline Int &shrb (int l = ) {
for (rg int i = ; i < c.size () - l; ++ i) c[i] = c[i + l];
c.resize (max (c.size () - l, ));
return *this;
}
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 () - ; i >= ; -- i)
if (c[i] != rhs.c[i]) return intcmp_ (c[i], rhs.c[i]);
return ;
}
inline Int div (const Int &rhs) {
assert (!rhs.c.empty ());
Int q, r;
rg int i;
if (rhs > *this) return ;
q.c.resize (c.size () - rhs.c.size () + );
rg int _l, _r, mid;
for (i = c.size () - ; i > c.size () - rhs.c.size (); -- i) r.shlb (), r += c[i];
for (i = c.size () - rhs.c.size (); i >= ; -- i) {
r.shlb ();
r += c[i];
if (r.Comp (rhs) < ) q.c[i] = ;
else {
_l = , _r = Big_B;
for (; _l != _r; ) {
mid = _l + _r >> ;
if ((rhs * mid).Comp (r) <= ) _l = mid + ;
else _r = mid;
}
q.c[i] = _l - , r -= rhs * q.c[i];
}
}
q.CrZ (), *this = r;
return q;
}
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 -= 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 () == ) out << "";
else {
out << rhs.c.back ();
for (rg int i = rhs.c.size () - ; i >= ; -- i)
out << std :: setfill ('') << std :: setw (Big_L) << rhs.c[i];
}
return out;
}
friend inline std :: istream &operator >> (std :: istream &in, Int &rhs) {
static char s[];
in >> s + ;
int Len = strlen (s + );
int v = ;
LL r = , p = ;
for (rg int i = Len; i >= ; -- i) {
++ v;
r = r + (s[i] - '') * p, p *= ;
if (v == Big_L) rhs.c.push_back (r), r = , v = , p = ;
}
if (v != ) rhs.c.push_back (r);
return in;
}
friend inline bool operator < (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) < ;
}
friend inline bool operator <= (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) <= ;
}
friend inline bool operator > (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) > ;
}
friend inline bool operator >= (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) >= ;
}
friend inline bool operator == (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) == ;
}
friend inline bool operator != (const Int &lhs, const Int &rhs) {
return lhs.Comp (rhs) != ;
}
#undef rg
};
Int a;
int Main () {
return ;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {
;
}
最新文章
- Spark MLlib 之 Naive Bayes
- 解析C#开发过程常见的编程模式
- How to pronounce symbols on keyboard
- python学习心得第四章
- 拼图游戏(js,C#,java三种语言)
- doPost方法与doGet方法
- Visual Studio 如何恢复默认设置
- android 21 隐式意图启动系统预定义activity
- maven上传自定义jar到本地仓库
- [Cycle.js] Hyperscript as our alternative to template languages
- Jquery遍历数组之$.inArray()方法介绍
- OpenGL缓冲区
- JS自定义对象以及相关成绩系统完整案例演示
- scrapy_简介页面和详情页面
- python中的randint,引入模块
- Pycharm 设置上下左右快捷键
- HDU 1848 Fibonacci again and again【博弈SG】
- Vue中router两种传参方式
- win7卸载IE11
- JqGrid 隐藏水平滚动条完美解决方案