vector<int> div(vector<int> &A, int &b) { vector<int> res; int r = 0; // 1 for (int i = 0; i < A.size(); i ++ ) { r = r * 10 + A[i]; // 2 res.push_back(r / b); // 3 r %= b; // 4 } reverse(res.begin(), res.end()); // 5 for (; res.size() > 1 && res.back() == 0;) res.pop_back(); b = r; return res; }
intmain() { string a; int b; cin >> a >> b; vector<int> A; for (int i = 0; i < a.length(); i ++ ) A.push_back(a[i] - '0'); vector<int> res; res = div(A, b); for (int i = res.size() - 1; i >= 0; i -- ) cout << res[i]; cout << endl << b; }