You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
632 B
32 lines
632 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 1e5 + 10;
|
|
int a[N], al, r;
|
|
void div(int a[], int &al, int b, int &r) {
|
|
r = 0;
|
|
for (int i = al - 1; i >= 0; i--) {
|
|
r = r * 10 + a[i];
|
|
a[i] = r / b;
|
|
r %= b;
|
|
}
|
|
// 去前导0
|
|
while (al > 0 && !a[al]) al--;
|
|
}
|
|
|
|
int main() {
|
|
string x;
|
|
int y;
|
|
|
|
cin >> x >> y;
|
|
|
|
for (int i = x.size() - 1; i >= 0; i--) a[al++] = x[i] - '0';
|
|
// 高精度除法
|
|
div(a, al, y, r);
|
|
|
|
// 输出
|
|
for (int i = al; i >= 0; i--) printf("%d", a[i]);
|
|
puts("");
|
|
printf("%d\n", r);
|
|
return 0;
|
|
} |