0% found this document useful (0 votes)
26 views3 pages

Bignum

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Bignum

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <bits/stdc++.

h>
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define __builtin_popcount __builtin_popcountll
#define __builtin_ctz __builtin_ctzll
//#define int long long
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define whole(a) a.begin(), a.end()
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define mirai ""
#define __Mirai_Kuriyama__ signed main()
template<class X, class Y>
bool minimize(X& x, const Y& y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
}
else return false;
}
template<class X, class Y>
bool maximize(X& x, const Y& y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return true;
}
else return false;
}
template<class T>
T Abs(const T& x) {
return (x < 0 ? -x : x);
}
const int INF = 1e9 + 7;
const ll oo = 1e18 + 7;
const int MAX = 1000005;
const int MOD = 1e9 + 7;
using namespace std;
string a, b;
string csl(string a, string b)
{
int du = 0;
int mid = 0;
string res = "";
a.insert(0, max(0, (int) (b.length() - a.length())), '0');
b.insert(0, max(0, (int) (a.length() - b.length())), '0');
for (int i = a.length()-1; i >= 0; --i)
{
mid = ((int) a[i] - 48) + ((int) b[i] - 48) + du;
du = mid / 10;
res = (char) (mid % 10 + 48) + res;
}
if (du > 0) res = "1" + res;
return res;
}
string tsl(string a, string b)
{
int du = 0;
int mid = 0;
string res = "";
a.insert(0, max(0, (int) (b.length() - a.length())), '0');
b.insert(0, max(0, (int) (a.length() - b.length())), '0');
for (int i = a.length()-1; i >= 0; --i)
{
mid = ((int) a[i] - 38) - ((int) b[i] - 48) - du;
du = (mid < 10) ? 1 : 0;
res = (char) (mid % 10 + 48) + res;
}
while (res[0] == '0' && res.length() > 1) res.erase(0, 1);
return res;
}
string nsb(string a, int b, int l)
{
string res = "";
int mid = 0;
int du = 0;
for (int i = a.length() - 1; i >= 0; --i)
{
mid = ((int) a[i] - 48) * b + du;
du = mid / 10;
res = (char) (mid % 10 + 48) + res;
}
if (du > 0)
{
string k = to_string(du);
res = k + res;
}
res.insert(res.length(), l, '0');
return res;
}

string nsl(string a, string b)


{
string res = "";
for (int i = b.length() - 1; i >= 0; --i)
{
string t = nsb(a, (int) b[i] - 48, b.length() - i - 1);
res = csl(res, t);
}
return res;
}
int cmp(string a, string b)
{
a.insert(0, max(0, (int)(b.length() - a.length())), '0');
b.insert(0, max(0, (int)(a.length() - b.length())), '0');
if (a > b) return 1;
if (a == b) return 2;
return 3;
}
string chsl(string a, string b, string t)
{
string tb[11];
tb[0] = "0";
for (int i = 1; i <= 10; ++i) tb[i] = csl(tb[i-1], b);

string hold = a.substr(0, b.length()-1);


cout << hold << endl;
string res = "";
for (int i = b.length()-1; i <= (int) a.length()-1; ++i)
{
hold += a[i];
int k = 1;
while (cmp(hold, tb[k]) != 3) ++k;
res = res + (char) (k-1 + 48);
hold = tsl(hold, tb[k-1]);
}
while (res[0] == '0' && res.length() > 1) res.erase(0, 1);
if (t == "div") return res;
else return hold;
}
void process(){
cin >> a >> b;
string ans = nsl(a, b);
cout << ans;
}
__Mirai_Kuriyama__
{
fastio
if (fopen(mirai".inp", "r")) {
freopen(mirai".inp", "r", stdin);
freopen(mirai".out", "w", stdout);
}
int Test = 1;
while (Test--) {
process();
}
return 0;
}

You might also like