typedeflonglong LL; LL r; // 计算当前被除数,或者说余数 constint N = 1e5 + 10; int A[N], b, C[N]; int la, lc;
voiddiv(int A[], int b, int C[]);
intmain(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin >> a >> b; lc = la = a.size(); // lc = la for (int i = la - 1; ~i; i -- ) A[la - 1 - i] = a[i] - '0'; // 翻转存入 div(A, b, C); for (int i = lc; ~i; i -- ) cout << C[i]; // 逆序输出 cout << endl << r << endl; return0; }
voiddiv(int A[], int b, int C[]){ r = 0; for (int i = la - 1; ~i; i -- ){ r = r * 10 + A[i]; // 被除数 C[la - 1 - i] = r / b; // 存商 r %= b; // 余数 } reverse(C, C + lc); while (lc && C[lc] == 0) lc -- ; // 处理多余0 }