版本比较
题解:P10414 [蓝桥杯 2023 国 A] 2023 次方
正文
增加 10 行删除 10 行
65 行未改动666768697070717273744 行未改动7980818283838485868723 行未改动11111211311411511511611711811962 行未改动18218318418518618618718818919015 行未改动20620720820921021021121221321435 行未改动25025125225325425425525625725860 行未改动31932032132232332332432532632714 行未改动34234334434534634634734834935014 行未改动36536636736836936937037137237321 行未改动39539639739839939940040140240334 行未改动65 行未改动 } inline void DelPre0() { while (len && v[len] == 0) --len; }
public: bool is_pos; int v[N], len; //by default, 0 is positive and 0 has length 0.4 行未改动 if (!IsZero()) ++len; for (int i = len; i; --i) v[i] = v[i - 1]; v[0] = x; }
//Constructors Bigint(): is_pos(1), len(0) { v[0] = 0; }23 行未改动 len = a.len; memcpy(v, a.v, (len + 1) * sizeof *v); return *this; }
//Add Bigint& operator++() { return *this += 1; } Bigint operator++(int) { Bigint tmp(*this); *this += 1; return tmp; } Bigint& operator+=(ll x) {62 行未改动 Bigint operator+(const Bigint &a) const { Bigint rst(*this); return rst += a; }
//Subtraction Bigint& operator--() { return *this += -1; } Bigint operator--(int) { Bigint tmp(*this); *this += -1; return tmp; } Bigint& operator-=(ll x) {15 行未改动 Bigint operator-(const Bigint &x) const { Bigint rst(*this), tmp(x); tmp.is_pos ^= 1; return rst += tmp; }
//Multiplication static const int FFT_LIM = 5000; Bigint& operator*=(int x) { if (!x) return *this = Bigint();35 行未改动 Bigint operator*(const Bigint &x) const { Bigint tmp(*this); return tmp *= x; }
//Division & modulo operation Bigint& operator/=(int x) { if (IsZero()) return *this; if (x == 0) {60 行未改动 Bigint operator%(const Bigint &a) const { Bigint tmp(*this); return tmp %= a; }
//Compare bool operator<(const Bigint &a) const { if (is_pos != a.is_pos) return !is_pos; if (len != a.len) return (len < a.len) ^ !is_pos;14 行未改动 } bool operator!=(const Bigint &a) const { return (a < *this) || (*this < a); }
//Input&Output string to_string() const { string ans; if (!is_pos) ans.append(1, '-');14 行未改动 } friend ostream& operator<<(ostream &out, const Bigint &a) { return out << a.to_string(); }
//Others friend Bigint abs(const Bigint &a) { Bigint tmp(a); tmp.is_pos = 1;21 行未改动 if (!tb.IsZero()) ta = tb; while (tm--) ta *= 2; return ta; }
//Debug inline void Debug(string info = "") const { cout << info << endl; printf("Positive? %d\n", is_pos);34 行未改动