/////////////////////integer.h
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;
#define MAXSIZE 256
/***************************
* @class name: BigInteger
* @author: LoongFee
* @date: 2009-11-03
****************************/
class BigInteger
{
public:
bool sign;
char modulus[MAXSIZE];
int ndigit;
public:
BigInteger(); //Defaulted constructor
BigInteger(const char* a); //Constructor with a value
BigInteger(const int& a);
BigInteger(const BigInteger& another); //Copy constructor
~BigInteger(); //Destructor
BigInteger abs(const BigInteger& another);
BigInteger mod(const BigInteger& another);
BigInteger gcd(const BigInteger& another); //the greatest common divisor
BigInteger gcd(const BigInteger& a1, const BigInteger& a2);
BigInteger lcm(const BigInteger& another); //the least common multiple
BigInteger lcm(const BigInteger& a1, const BigInteger& a2);
////Overload operators
BigInteger& operator = (const BigInteger& another);
BigInteger& operator = (const string& another);
BigInteger& operator = (const int& another);
BigInteger operator + (const BigInteger& another);
BigInteger& operator += (const BigInteger& another);
BigInteger operator - (const BigInteger& another);
BigInteger& operator -= (const BigInteger& another);
BigInteger operator - ();
BigInteger operator * (const BigInteger& another);
BigInteger& operator *= (const BigInteger& another);
BigInteger operator / (const BigInteger& another);
BigInteger& operator /= (const BigInteger& another);
BigInteger operator % (const BigInteger& another);
BigInteger& operator %= (const BigInteger& another);
BigInteger& operator ++ ();
BigInteger& operator -- ();
BigInteger operator ++(int);
BigInteger operator --(int);
bool operator >= (const BigInteger& another);
bool operator <= (const BigInteger& another);
bool operator == (const BigInteger& another);
bool operator != (const BigInteger& another);
bool operator > (const BigInteger& another);
bool operator < (const BigInteger& another);
friend ostream& operator <<(ostream& o, const BigInteger& myInt)
{
if(1 == myInt.sign)
cout<<'-';
cout<<myInt.modulus;
return o;
}
friend istream& operator >>(istream& i, BigInteger& myInt)
{
char tmp[MAXSIZE];
cin>>tmp;
myInt.sign = (tmp[0] == '-') ? 1 : 0;
int pos = myInt.sign;
while('\0' != tmp[pos])
{
myInt.modulus[pos - myInt.sign] = tmp[pos++];
}
myInt.ndigit = (pos - myInt.sign);
myInt.modulus[myInt.ndigit] = '\0';
return i;
}
};