#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Bigint {
int len;
int a[1005];
bool is_negative;
// 构造函数
Bigint(ll x = 0) {
memset(a, 0, sizeof(a));
is_negative = x < 0;
x = abs(x);
for (len = 1; x; len++) {
a[len] = x % 10;
x /= 10;
}
len--;
if (len == 0) len = 1;
}
Bigint(const string &s) {
memset(a, 0, sizeof(a));
int start = 0;
is_negative = false;
if (s[0] == '-') {
is_negative = true;
start = 1;
}
len = s.length() - start;
for (int i = 0; i < len; i++) {
a[len - i] = s[start + i] - '0';
}
flatten(len);
if (len == 1 && a[1] == 0) {
is_negative = false;
}
}
int &operator[](ll i) { return a[i]; }
void flatten(int L) {
len = L;
for (int i = 1; i <= len; i++) {
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
while (len > 1 && !a[len]) len--;
}
bool operator<(const Bigint &b) const {
if (is_negative != b.is_negative) return is_negative;
if (len != b.len) return (len < b.len) ^ is_negative;
for (int i = len; i >= 1; i--) {
if (a[i] != b.a[i]) return (a[i] < b.a[i]) ^ is_negative;
}
return false;
}
bool operator>(const Bigint &b) const { return b < *this; }
bool operator<=(const Bigint &b) const { return !(b < *this); }
bool operator>=(const Bigint &b) const { return !(*this < b); }
bool operator==(const Bigint &b) const {
if (is_negative != b.is_negative || len != b.len) return false;
for (int i = 1; i <= len; i++) {
if (a[i] != b.a[i]) return false;
}
return true;
}
bool operator!=(const Bigint &b) const { return !(*this == b); }
Bigint operator+(Bigint b) {
if (is_negative) return b - (-*this);
if (b.is_negative) return *this - (-b);
Bigint c;
int max_len = max(len, b.len);
for (int i = 1; i <= max_len; i++) {
c[i] += a[i] + b.a[i];
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
c.flatten(max_len + 1);
return c;
}
Bigint operator-(Bigint b) {
if (b.is_negative) return *this + (-b);
if (is_negative) return -(-*this + b);
if (*this < b) return -(b - *this);
Bigint c;
for (int i = 1; i <= len; i++) {
c[i] += a[i] - b.a[i];
if (c[i] < 0) {
c[i] += 10;
c[i + 1]--;
}
}
c.flatten(len);
return c;
}
Bigint operator*(Bigint b) {
Bigint c;
c.is_negative = is_negative ^ b.is_negative;
for (int i = 1; i <= len; i++) {
for (int j = 1; j <= b.len; j++) {
c[i + j - 1] += a[i] * b.a[j];
c[i + j] += c[i + j - 1] / 10;
c[i + j - 1] %= 10;
}
}
c.flatten(len + b.len + 2);
return c;
}
Bigint operator/(Bigint b) {
if (b == Bigint(0)) throw runtime_error("Division by zero");
Bigint c, current;
c.is_negative = is_negative ^ b.is_negative;
c.len = len;
for (int i = len; i >= 1; i--) {
current = current * Bigint(10) + Bigint(a[i]);
int x = 0;
while (current >= b) {
current = current - b;
x++;
}
c[i] = x;
}
c.flatten(len);
return c;
}
Bigint operator%(Bigint b) {
if (b == Bigint(0)) throw runtime_error("Division by zero");
return *this - (*this / b) * b;
}
Bigint operator-() const {
Bigint c = *this;
c.is_negative = !is_negative;
return c;
}
friend istream &operator>>(istream &is, Bigint &x) {
string s;
is >> s;
x = Bigint(s);
return is;
}
friend ostream &operator<<(ostream &os, const Bigint &x) {
if (x.is_negative) os << '-';
for (int i = x.len; i >= 1; i--) {
os << x.a[i];
}
if (x.len == 0) os << '0';
return os;
}
void Swap(Bigint &b) {
swap(len, b.len);
swap(is_negative, b.is_negative);
for (int i = 0; i < 1005; i++) {
swap(a[i], b[i]);
}
}
string toString() const {
string s;
if (is_negative) s += "-";
for (int i = len; i >= 1; i--) {
s += to_string(a[i]);
}
return s.empty() ? "0" : s;
}
string cf(const Bigint& cs) {
if (cs == Bigint(0)) {
throw runtime_error("Division by zero");
}
string res;
if (is_negative ^ cs.is_negative) {
res += "-";
}
Bigint zs, r;
for (int i = len; i >= 1; i--) {
r = r * Bigint(10) + Bigint(a[i]);
int num = 0;
while (r >= cs) {
r = r - cs;
num++;
}
zs[i] = num;
}
zs.flatten(len);
if (zs.len == 0) res += "0";
for (int i = zs.len; i >= 1; i--) {
res += to_string(zs.a[i]);
}
if (r != Bigint(0)) {
res += ".";
unordered_map<string, int> mp;
string xs;
bool f = false;
int st = -1;
while (r != Bigint(0)) {
r = r * Bigint(10);
string rs = r.toString();
if (mp.count(rs)) {
st = mp[rs];
f = 1;
break;
}
mp[rs] = xs.length();
ll num = 0;
while (r >= cs) {
r = r - cs;
num++;
}
xs += to_string(num);
}
if (f) {
res += xs.substr(0, st);
res += "[" + xs.substr(st) + "]";
} else {
res += xs;
}
}
return res;
}
};
int main() {
// 测试代码
Bigint a, b;
cin >> a >> b;
cout << "a + b = " << a + b << endl;
cout << "a - b = " << a - b << endl;
cout << "a * b = " << a * b << endl;
cout << "a // b = " << a / b << endl;
cout << "a % b = " << a % b << endl;
cout << "a / b = " << a.cf(b) << endl;
return 0;
}