正文
增加 159 行删除 2 行
31 行未改动32333435363738394031 行未改动7273747576777879804 行未改动8586878831 行未改动[](https://www.luogu.com.cn/user/1005493)## 个人常用头文件g++ 指令:```-Wall -O2 -std=c++20 -Wl,--stack=268435456``````cpp#include<bits/stdc++.h>31 行未改动write(x / 10);putchar(x % 10 + '0');return;}}using namespace florr;signed main(){4 行未改动}/**/```31 行未改动32333435363738394031 行未改动72737475767778794 行未改动8485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424531 行未改动[](https://www.luogu.com.cn/user/1005493)## 个人常用头文件g++ 指令:```-Wall -O2 -std=c++20 -Wl,--stack=2147483648``````cpp#include<bits/stdc++.h>31 行未改动write(x / 10);putchar(x % 10 + '0');return;}}using namespace florr;signed main(){4 行未改动}/**/```## 高精度板子```cpp#include<bits/stdc++.h>#define int long long//#define putchar putchar_unlocked//#define getchar getchar_unlocked#define rep(K,F,T) for(int K = F;K <= T;K++)#define rip(K,F,T) for(int K = F;K >= T;K--)using namespace std;namespace florr{inline int read(){int x = 0, f = 1;char ch = getchar();while (ch<'0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();return x * f;}void write(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)write(x / 10);putchar(x % 10 + '0');return;}}using namespace florr;struct BigInt{static const int BASE = 100000000, DIG = 8; // 1e8 进制,每块 8 位十进制vector<int> a; // a[0] 是最低位,只存非负整数BigInt(){}BigInt(int x){ while(x > 0) a.push_back(x % BASE), x /= BASE; }bool zero() const { return a.empty(); }void trim(){ while(!a.empty() && a.back() == 0) a.pop_back(); return; }void read() // 读入一个非负整数(忽略前导空白){a.clear();char ch = getchar();while (ch < '0' || ch > '9')ch = getchar();static char buf[1000005];int len = 0;while (ch >= '0' && ch <= '9')buf[len ++] = ch, ch = getchar();rip(i, len - 1, 0){ // 从低位往高位,每 8 位压成一块int l = max(0ll, i - DIG + 1), v = 0;rep(k, l, i) v = v * 10 + (buf[k] - '0');a.push_back(v);i = l;}trim();return;}void print(){if(a.empty()){putchar('0');return;}write(a.back());rip(i, (int)a.size() - 2, 0){ // 后面的块补足 8 位int v = a[i];char buf[DIG];rip(k, DIG - 1, 0) buf[k] = char('0' + v % 10), v /= 10;rep(k, 0, DIG - 1) putchar(buf[k]);}return;}friend int cmp(const BigInt &x,const BigInt &y){if(x.a.size() != y.a.size())return x.a.size() < y.a.size() ? -1 : 1;rip(i, (int)x.a.size() - 1, 0)if(x.a[i] != y.a[i])return x.a[i] < y.a[i] ? -1 : 1;return 0;}friend bool operator< (const BigInt &x,const BigInt &y){ return cmp(x, y) < 0; }friend bool operator> (const BigInt &x,const BigInt &y){ return cmp(x, y) > 0; }friend bool operator<=(const BigInt &x,const BigInt &y){ return cmp(x, y) <= 0; }friend bool operator>=(const BigInt &x,const BigInt &y){ return cmp(x, y) >= 0; }friend bool operator==(const BigInt &x,const BigInt &y){ return cmp(x, y) == 0; }friend bool operator!=(const BigInt &x,const BigInt &y){ return cmp(x, y) != 0; }friend BigInt operator+ (const BigInt &x,const BigInt &y){BigInt z;int carry = 0, len = max(x.a.size(), y.a.size());rep(i, 0, len - 1){int s = carry;if(i < (int)x.a.size()) s += x.a[i];if(i < (int)y.a.size()) s += y.a[i];z.a.push_back(s % BASE), carry = s / BASE;}if(carry) z.a.push_back(carry);return z;}friend BigInt operator- (const BigInt &x,const BigInt &y) // 要求 x >= y{BigInt z = x;int borrow = 0;rep(i, 0, (int)z.a.size() - 1){z.a[i] -= borrow + (i < (int)y.a.size() ? y.a[i] : 0);if(z.a[i] < 0) z.a[i] += BASE, borrow = 1;else borrow = 0;}z.trim();return z;}friend BigInt operator* (const BigInt &x,const BigInt &y){BigInt z;if(x.zero() or y.zero()) return z;z.a.assign(x.a.size() + y.a.size(), 0);rep(i, 0, (int)x.a.size() - 1){int carry = 0;rep(j, 0, (int)y.a.size() - 1){carry += z.a[i + j] + x.a[i] * y.a[j];z.a[i + j] = carry % BASE;carry /= BASE;}z.a[i + y.a.size()] += carry;}z.trim();return z;}BigInt& operator+= (const BigInt &y){ *this = *this + y; return *this; }BigInt& operator-= (const BigInt &y){ *this = *this - y; return *this; }BigInt& operator*= (const BigInt &y){ *this = *this * y; return *this; }};BigInt x, y, z;signed main(){// freopen(".in","r",stdin);// freopen(".out","w",stdout);x.read(), y.read();z = x + y, z.print(), putchar('\n');z = x * y, z.print(), putchar('\n');if(x >= y) z = x - y, z.print(), putchar('\n');else putchar('-'), z = y - x, z.print(), putchar('\n');return 0;}```