#include <bits/stdc++.h>
using namespace std;
class bignum
{
private:
/*
传入两个高精度正数wa和wb。
如果wa小于wb返回true否则返回false。
*/
bool cmp(const string &wa, const string &wb)
{
if (wa.size() < wb.size())
return 1;
if (wa.size() > wb.size())
return 0;
int len = wa.size();
for (int i = 0; i < len; i++)
{
if (wa[i] == wb[i])
continue;
return wa[i] < wb[i];
}
return 0;
}
/*
传进来两个高精度整数返回wa - wb的值。
要求wa >= wb,例如:wa = 123, wb = 24。sub(wa, wb) = 99.
*/
string sub(const string &wa, const string &wb)
{
string a = wa, b = wb;
reverse(a.begin(), a.end()), reverse(b.begin(), b.end());
string res = "";
for (int i = 0, t = 0; i < (int)a.size(); i++)
{
t = (a[i] - '0') - t;
if (i < (int)b.size())
t -= (b[i] - '0');
res.push_back((t + 10) % 10 + '0');
t < 0 ? t = 1 : t = 0;
}
while ((int)res.size() > 1 && res.back() == '0')
res.pop_back();
reverse(res.begin(), res.end());
return res;
}
/*
传进来一个高精度整数wa和一个int类型的整数b。
返回wa / b的值。
例如:wa = 124, b = 4, div(wa, b) = 31.
*/
string div(const string &wa, int b)
{
string a = wa, res = "";
reverse(a.begin(), a.end());
int r = 0;
for (int i = (int)a.size() - 1; i >= 0; i--)
{
r = r * 10 + (a[i] - '0');
res.push_back((r / b) + '0');
r %= b;
}
reverse(res.begin(), res.end());
while ((int)res.size() > 1 && res.back() == '0')
res.pop_back();
reverse(res.begin(), res.end());
return res;
}
/*
传进来一个高精度整数wa和一个int类型的整数b。
返回wa * b的值。
例如:wa = 124, b = 4, mul(wa, b) = 496.
*/
string mul(const string &wa, int b)
{
string a = wa, res = "";
reverse(a.begin(), a.end());
int t = 0;
for (int i = 0; i < (int)a.size() || t; i++)
{
if (i < (int)a.size())
t += (a[i] - '0') * b;
res.push_back((t % 10) + '0');
t /= 10;
}
while ((int)res.size() > 1 && res.back() == 0)
res.pop_back();
reverse(res.begin(), res.end());
return res;
}
public:
string num;
bignum(string b = "0")
{
num = b;
}
/*
传进来一个高精度整数,如果是偶数返回true,奇数返回false.
*/
bool check(const string &a)
{
return !((a.back() - '0') & 1);
}
bignum operator*(int b)
{
return bignum(mul(this->num, b));
}
bignum operator/(int b)
{
return bignum(div(this->num, b));
}
bignum operator-(string b)
{
return bignum(sub(this->num, b));
}
bool operator<(string b)
{
return cmp(this->num, b);
}
bool operator>(string b)
{
return cmp(b, this->num);
}
void operator=(string a)
{
this->num = a;
}
};