不实用的高精
推荐一个实用小高精:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| struct BigInt { const static long long base = 1e13; long long s[2]; friend BigInt operator + (BigInt a, const BigInt b) { a.s[0] += b.s[0]; a.s[1] += b.s[1]; if (a.s[0] >= base) ++a.s[1], a.s[0] -= base; return a; } friend int operator % (BigInt a, int b) { return ((a.s[1] % b) * base + a.s[0]) % b; } friend BigInt operator / (BigInt a, int b) { BigInt c; c.s[1] = a.s[1] / b; c.s[0] = ((a.s[1] % b) * base + a.s[0]) / b; return c; } void print() { if (s[1]) printf("%lld%13lld", s[1], s[0]); else printf("%lld", s[0]); } };
|
乘法不用考虑,用 s[1] * s[1] 就炸了。减法还要考虑负数(如果需要的话)。