#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
string sA, sB; // 输入大整数
int aLen, a[MAXN + 5]; // 存第一个大整数
int bLen, b[MAXN + 5]; // 存第二个大整数
int cLen, c[MAXN + 5]; // 存第二个大整数
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// 用字符串读入两个大整数
cin >> sA >> sB;
// 转换、存入 a[] b[]
aLen = sA.size();
for (int i = 0; i <= aLen - 1; i++)
a[i] = sA[aLen - i - 1] - '0';
bLen = sB.size();
for (int i = 0; i <= bLen - 1; i++)
b[i] = sB[bLen - i - 1] - '0';
// 相加
cLen = max(aLen, bLen);
for (int i = 0; i <= cLen - 1; i++)
c[i] = a[i] + b[i];
// 进位:除了最高位之外的进位
for (int i = 0; i <= cLen - 2; i++)
if (c[i] >= 10)
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
// 进位:最高位扩展
while (c[cLen - 1] >= 10)
{
c[cLen] = c[cLen - 1] / 10;
c[cLen - 1] %= 10;
cLen++;
}
// 去掉前导0
while (cLen > 1 && c[cLen - 1] == 0)
cLen--;
// 输出
for (int i = cLen - 1; i >= 0; i--)
cout << c[i];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 201;
string sA, sB; // 输入大整数
int aLen, a[MAXN + 5]; // 存第一个大整数
int bLen, b[MAXN + 5]; // 存第二个大整数
int cLen, c[MAXN + 5]; // 存第二个大整数
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
// 用字符串读入两个大整数
cin >> sA >> sB;
// 保证做大减小
if (sA.size() < sB.size() ||
sA.size() == sB.size() && sA < sB)
{
cout << "-";
swap(sA, sB);
}
// 转换、存入 a[] b[]
aLen = sA.size();
for (int i = 0; i <= aLen - 1; i++)
a[i] = sA[aLen - i - 1] - '0';
bLen = sB.size();
for (int i = 0; i <= bLen - 1; i++)
b[i] = sB[bLen - i - 1] - '0';
// 相减
cLen = aLen;
for (int i = 0; i <= cLen - 1; i++)
c[i] = a[i] - b[i];
// 借位
for (int i = 0; i <= cLen - 2; i++)
if (c[i] < 0)
{
c[i] += 10;
c[i + 1] -= 1;
}
// 去掉前导0
while (cLen > 1 && c[cLen - 1] == 0)
cLen--;
// 输出
for (int i = cLen - 1; i >= 0; i--)
cout << c[i];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n;
int len, a[35660 + 5];
int main()
{
cin >> n;
// 构建一个高精度的 1
len = 1;
a[0] = 1;
// 把 1~n 乘进去
for (int i = 1; i <= n; i++)
{
// 把每一位都乘 i
for (int j = 0; j <= len - 1; j++)
a[j] *= i;
// 除了最高位之外的进位
for (int j = 0; j <= len - 2; j++)
{
a[j + 1] += a[j] / 10;
a[j] %= 10;
}
// 最高位扩展
while (a[len - 1] >= 10)
{
a[len] = a[len - 1] / 10;
a[len - 1] %= 10;
len++;
}
}
// 从高到低位输出
// cout << len << "\n";
for (int i = len - 1; i >= 0; i--)
cout << a[i];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int LEN = 200;
string A, B;
int aLen, bLen, cLen;
int a[LEN + 5], b[LEN + 5], c[LEN + LEN + 5];
int main()
{
// 以字符串形式输入
cin >> A >> B;
// 转换为数字并翻转存入数组
aLen = A.size();
bLen = B.size();
cLen = aLen + bLen - 1; // 相乘的结果,在进位之前的长度
for (int i = 0; i < aLen; i++)
a[aLen - i - 1] = A[i] - '0';
for (int i = 0; i < bLen; i++)
b[bLen - i - 1] = B[i] - '0';
// 相乘
for (int i = 0; i < aLen; i++)
for (int j = 0; j < bLen; j++)
c[i + j] += a[i] * b[j];
// 进位
for (int i = 0; i < cLen - 1; i++)
{
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
// 最高位扩展
while (c[cLen - 1] >= 10)
{
c[cLen] = c[cLen - 1] / 10;
c[cLen - 1] %= 10;
cLen++;
}
// 前导 0 去除
while (cLen > 1 && c[cLen - 1] == 0)
cLen--;
// 输出
for (int i = cLen - 1; i >= 0; i--)
cout << c[i];
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int LEN = 100;
string N;
int nLen;
int n[LEN + 5];
int ansLen;
int ans[LEN + 5];
int main()
{
cin >> N;
// M 翻转并转换为对应的数字
nLen = N.size();
for (int i = 0; i < nLen; i++)
n[nLen - i - 1] = N[i] - '0';
// 除以 13
ansLen = nLen;
int now = 0; // 当前除数
for (int i = ansLen - 1; i >= 0; i--)
{
now = now * 10 + n[i];
ans[i] = now / 13;
now = now % 13;
}
// 去掉前导 0
while (ansLen > 1 && ans[ansLen - 1] == 0)
ansLen--;
// 输出
for (int i = ansLen - 1; i >= 0; i--)
cout << ans[i];
cout << "\n";
cout << now << "\n";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int LEN = 300;
string A, B;
int cFlag;
int aLen, bLen, cLen;
int a[LEN + 5], b[LEN + 5], c[LEN + 5];
// 比大小,比较 a 的 up~down 这些位置是否大于等于 b
// 保证没有多余的前导 0
bool cmp(int up, int down)
{
if (up - down + 1 < bLen)
return false;
if (up - down + 1 > bLen)
return true;
for (int i = up; i >= down; i--)
{
if (a[i] < b[i - down])
return false;
if (a[i] > b[i - down])
return true;
}
return true;
}
// 比大小,将 a 的 up~down 这些位置减去 b
// 保证没有多余的前导 0
void sub(int up, int down)
{
for (int i = 0; i < bLen; i++)
a[down + i] -= b[i];
for (int i = down; i <= up; i++)
if (a[i] < 0)
{
a[i + 1]--;
a[i] += 10;
}
}
int main()
{
// 以字符串形式输入
cin >> A >> B;
// 转换为数字并翻转存入数组
aLen = A.size();
bLen = B.size();
cLen = aLen; // 商去除前导 0 之前的长度
for (int i = 0; i < aLen; i++)
a[aLen - i - 1] = A[i] - '0';
for (int i = 0; i < bLen; i++)
b[bLen - i - 1] = B[i] - '0';
// A / B = C,余数留在 A 里面
int up = aLen - 1;
for (int down = aLen - 1; down >= 0; down--)
{
while (up > down && a[up] == 0)
up--;
while (cmp(up, down))
{
c[down]++;
sub(up, down);
while (up > down && a[up] == 0)
up--;
}
}
// 去除前导 0
while (cLen > 1 && c[cLen - 1] == 0)
cLen--;
while (aLen > 1 && a[aLen - 1] == 0)
aLen--;
// 输出
for (int i = cLen - 1; i >= 0; i--)
cout << c[i];
cout << "\n";
for (int i = aLen - 1; i >= 0; i--)
cout << a[i];
cout << "\n";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct BigIntTiny
{
int sign;
std::vector<int> v;
BigIntTiny() : sign(1) {}
BigIntTiny(const std::string &s) { *this = s; }
BigIntTiny(int v)
{
char buf[21];
sprintf(buf, "%d", v);
*this = buf;
}
void zip(int unzip)
{
if (unzip == 0)
{
for (int i = 0; i < (int)v.size(); i++)
v[i] = get_pos(i * 4) + get_pos(i * 4 + 1) * 10 + get_pos(i * 4 + 2) * 100 + get_pos(i * 4 + 3) * 1000;
}
else
for (int i = (v.resize(v.size() * 4), (int)v.size() - 1), a; i >= 0; i--)
a = (i % 4 >= 2) ? v[i / 4] / 100 : v[i / 4] % 100, v[i] = (i & 1) ? a / 10 : a % 10;
setsign(1, 1);
}
int get_pos(unsigned pos) const { return pos >= v.size() ? 0 : v[pos]; }
BigIntTiny &setsign(int newsign, int rev)
{
for (int i = (int)v.size() - 1; i > 0 && v[i] == 0; i--)
v.erase(v.begin() + i);
sign = (v.size() == 0 || (v.size() == 1 && v[0] == 0)) ? 1 : (rev ? newsign * sign : newsign);
return *this;
}
std::string to_str() const
{
BigIntTiny b = *this;
std::string s;
for (int i = (b.zip(1), 0); i < (int)b.v.size(); ++i)
s += char(*(b.v.rbegin() + i) + '0');
return (sign < 0 ? "-" : "") + (s.empty() ? std::string("0") : s);
}
bool absless(const BigIntTiny &b) const
{
if (v.size() != b.v.size())
return v.size() < b.v.size();
for (int i = (int)v.size() - 1; i >= 0; i--)
if (v[i] != b.v[i])
return v[i] < b.v[i];
return false;
}
BigIntTiny operator-() const
{
BigIntTiny c = *this;
c.sign = (v.size() > 1 || v[0]) ? -c.sign : 1;
return c;
}
BigIntTiny &operator=(const std::string &s)
{
if (s[0] == '-')
*this = s.substr(1);
else
{
for (int i = (v.clear(), 0); i < (int)s.size(); ++i)
v.push_back(*(s.rbegin() + i) - '0');
zip(0);
}
return setsign(s[0] == '-' ? -1 : 1, sign = 1);
}
bool operator<(const BigIntTiny &b) const
{
return sign != b.sign ? sign < b.sign : (sign == 1 ? absless(b) : b.absless(*this));
}
bool operator==(const BigIntTiny &b) const { return v == b.v && sign == b.sign; }
BigIntTiny &operator+=(const BigIntTiny &b)
{
if (sign != b.sign)
return *this = (*this) - -b;
v.resize(std::max(v.size(), b.v.size()) + 1);
for (int i = 0, carry = 0; i < (int)b.v.size() || carry; i++)
{
carry += v[i] + b.get_pos(i);
v[i] = carry % 10000, carry /= 10000;
}
return setsign(sign, 0);
}
BigIntTiny operator+(const BigIntTiny &b) const
{
BigIntTiny c = *this;
return c += b;
}
void add_mul(const BigIntTiny &b, int mul)
{
v.resize(std::max(v.size(), b.v.size()) + 2);
for (int i = 0, carry = 0; i < (int)b.v.size() || carry; i++)
{
carry += v[i] + b.get_pos(i) * mul;
v[i] = carry % 10000, carry /= 10000;
}
}
BigIntTiny operator-(const BigIntTiny &b) const
{
if (sign != b.sign)
return (*this) + -b;
if (absless(b))
return -(b - *this);
BigIntTiny c;
for (int i = 0, borrow = 0; i < (int)v.size(); i++)
{
borrow += v[i] - b.get_pos(i);
c.v.push_back(borrow);
c.v.back() -= 10000 * (borrow >>= 31);
}
return c.setsign(sign, 0);
}
BigIntTiny operator*(const BigIntTiny &b) const
{
if (b < *this)
return b * *this;
BigIntTiny c, d = b;
for (int i = 0; i < (int)v.size(); i++, d.v.insert(d.v.begin(), 0))
c.add_mul(d, v[i]);
return c.setsign(sign * b.sign, 0);
}
BigIntTiny operator/(const BigIntTiny &b) const
{
BigIntTiny c, d;
d.v.resize(v.size());
double db = 1.0 / (b.v.back() + (b.get_pos((unsigned)b.v.size() - 2) / 1e4) +
(b.get_pos((unsigned)b.v.size() - 3) + 1) / 1e8);
for (int i = (int)v.size() - 1; i >= 0; i--)
{
c.v.insert(c.v.begin(), v[i]);
int m = (int)((c.get_pos((int)b.v.size()) * 10000 + c.get_pos((int)b.v.size() - 1)) * db);
c = c - b * m, d.v[i] += m;
while (!(c < b))
c = c - b, d.v[i] += 1;
}
return d.setsign(sign * b.sign, 0);
}
BigIntTiny operator%(const BigIntTiny &b) const { return *this - *this / b * b; }
bool operator>(const BigIntTiny &b) const { return b < *this; }
bool operator<=(const BigIntTiny &b) const { return !(b < *this); }
bool operator>=(const BigIntTiny &b) const { return !(*this < b); }
bool operator!=(const BigIntTiny &b) const { return !(*this == b); }
};
int main(){
BigIntTiny a, b;
string sa, sb;
cin >> sa >> sb;
a = sa;
b = sb;
cout << (a / b).to_str() << endl << (a % b).to_str() << endl;
}