Advertisement
bartekltg

biggestbignum

Sep 30th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. class biggestbignum
  2. {
  3.     const static uint32_t M=1000000000;
  4.     uint32_t a,b;
  5. public:
  6.     biggestbignum ( uint32_t a_, uint32_t b_ ): a(a_), b(b_) {};
  7.     biggestbignum ( uint32_t a_): a(a_), b(0) {};
  8.  
  9.     biggestbignum operator * (const biggestbignum &other) const
  10.     {
  11.         uint64_t A = a *(uint64_t) other.a;
  12.         uint64_t B = (a *(uint64_t) other.b) + (b *(uint64_t) other.a) + A/M;
  13.         return biggestbignum ( A%M, B%M );
  14.     }
  15.     biggestbignum operator + (const biggestbignum &other)
  16.     {
  17.         biggestbignum res( (a+other.a), (b+other.b) );
  18.         res.b+=res.a/M;
  19.         res.b%=M;
  20.         res.a%=M;
  21.         return res;
  22.     }
  23.     friend ostream& operator<<(ostream& os, const biggestbignum& x);
  24. };
  25.  
  26. ostream& operator<<(ostream& os, const biggestbignum& x)
  27. {
  28.     if (x.b>0)
  29.         os<<x.b<<setw(9)<<std::setfill ('0');
  30.     os<<x.a;//<<" hi "<<x.b<<" lo "<<x.a;
  31.     return os;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement