Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class biggestbignum
- {
- const static uint32_t M=1000000000;
- uint32_t a,b;
- public:
- biggestbignum ( uint32_t a_, uint32_t b_ ): a(a_), b(b_) {};
- biggestbignum ( uint32_t a_): a(a_), b(0) {};
- biggestbignum operator * (const biggestbignum &other) const
- {
- uint64_t A = a *(uint64_t) other.a;
- uint64_t B = (a *(uint64_t) other.b) + (b *(uint64_t) other.a) + A/M;
- return biggestbignum ( A%M, B%M );
- }
- biggestbignum operator + (const biggestbignum &other)
- {
- biggestbignum res( (a+other.a), (b+other.b) );
- res.b+=res.a/M;
- res.b%=M;
- res.a%=M;
- return res;
- }
- friend ostream& operator<<(ostream& os, const biggestbignum& x);
- };
- ostream& operator<<(ostream& os, const biggestbignum& x)
- {
- if (x.b>0)
- os<<x.b<<setw(9)<<std::setfill ('0');
- os<<x.a;//<<" hi "<<x.b<<" lo "<<x.a;
- return os;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement