-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1017.cpp
More file actions
45 lines (40 loc) · 1.06 KB
/
1017.cpp
File metadata and controls
45 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct BigInt {
vector<int> digits;
friend istream& operator>>(istream &in, BigInt &num) {
string str;
in >> str;
for (auto it = str.rbegin(); it != str.rend(); it++)
num.digits.push_back(*it - '0');
return in;
}
friend ostream& operator<<(ostream &out, const BigInt &num) {
for (auto it = num.digits.rbegin(); it != num.digits.rend(); it++)
cout << *it;
return out;
}
friend BigInt divide(BigInt a, int b, int &r) {
r = 0;
BigInt c;
const int n = a.digits.size();
c.digits.resize(n);
for (int i = n - 1; i >= 0; i--) {
r = r * 10 + a.digits[i];
c.digits[i] = r / b;
r %= b;
}
while (c.digits.size() > 1 && c.digits.back() == 0)
c.digits.pop_back();
return c;
}
};
int main() {
BigInt a;
int b, r;
cin >> a >> b;
BigInt c = divide(a, b, r);
cout << c << " " << r << endl;
}