$$\color{red}{算法}\color{blue}{基础课}\color{purple}{笔记and题解}\color{green}{汇总}$$
笔记:
高精除以低精。
依次把每一位加进余数,除以$b$,最后再取模。
代码:
#include <bits/stdc++.h>
using namespace std;
string a;
vector<int> A;
int B, c;
vector<int> div(vector<int> &A, int b, int &r) {
vector<int> C;
c = 0;
for (int i = A.size() - 1; i >= 0; i--) {
c = c * 10 + A[i];
C.push_back(r / b);
c %= b;
}
reverse(C.begin(), C.end());
while (C.size() > 1 && C.back() == 0) C.pop_back();
return C;
}
int main() {
cin >> a >> B;
for (int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0');
auto C = div(A, B, c);
for (int i = C.size() - 1; i >= 0; i--) cout << C[i];
printf("\n%d\n", c);
return 0;
}
高精度 / 高精度 没有写嘛?