bignum bignum_subtract(bignum& a, bignum& b) { bignum c; if (b.size() > a.size()) c.push_back(0); else if (a.size() == b.size() && b.back() > a.back()) c.push_back(0); else { int k; for (unsigned int i = 0; i < a.size() + b.size(); i++) { k = 0; if (i < a.size()) k += a[i]; if (i < b.size()) k -= b[i]; c.push_back(k); } for (unsigned int i = 0; i < c.size() - 1; i++) { while (c[i] < 0) { c[i + 1] -= 1; c[i] += BASE; } } } c = bignum_popzeroes(c); return c; }
bignum bignum_popzeroes(bignum& c) { if (c.size() > 1) { while (c.size() > 1 && c.back() == 0) c.pop_back(); } return c; }
void bignum_print(ostream& print, bignum& c) { c = bignum_popzeroes(c); cout << c.back(); if (c.size() - 2 >= 0) { for (unsigned int i = c.size()-2; i + 1 > 0; i--) cout << setfill('0') << setw(3) << c[i]; } }