Thông tin
include <iostream>
include <string>
include <algorithm>
using namespace std; bool ss(string a, string b) { while(a.length() < b.length()) a = '0' + a; while(b.length() < a.length()) b = '0' + b; return a >= b; } string congsl(string a, string b) { int nho = 0; string c = ""; while(a.length() < b.length()) a = '0' + a; while(b.length() < a.length()) b = '0' + b; for(int i = a.length() - 1; i >= 0; --i) { nho += a[i] + b[i] - 96; c = char(nho%10+48) + c; nho /= 10; } c = char(nho%10+48) + c; while(c[0] == '0' and c.length() > 1) c.erase(0,1); return c; } string trusl(string a, string b) { int muon = 0; string c = ""; while(a.length() < b.length()) a = '0' + a; while(b.length() < a.length()) b = '0' + b; for(int i = a.length() - 1; i >= 0; --i) if(a[i] - b[i] - muon >= 0) {c = char(a[i]-b[i]-muon+48) + c; muon = 0;} else {c = char(a[i]+10-b[i]-muon+48) + c; muon = 1;} while(c[0] == '0' and c.length() > 1) c.erase(0,1); return c; } string nhanslsl(string a, string b) { int nho; string c = ""; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); for(int i = 0; i < a.size() + b.size(); i++) c += '0'; for(int i = 0; i < a.length(); ++i) { nho = 0; for(int j = 0; j < b.length(); ++j) { nho = nho + c[i+j] - 48 + (a[i] - 48)*(b[j] - 48); c[i+j] = char(nho % 10 + 48); nho /= 10; } c[i+b.length()] += nho; } for (int i = 0; i < c.length()/2; ++i) swap(c[i], c[c.length()-i-1]); while(c[0] == '0' and c.length() > 1) c.erase(0,1); return c; } string nhanslsn(string a, long m) { long i, r = 0; for (i = a.size() - 1; i >= 0; i--) { r += (a[i] - '0') * m; a[i] = char(r % 10 + '0'); r /= 10; } while (r > 0) { a = char(r % 10 + '0') + a; r /= 10; } return a; } string chiaslsl(string a, string b) { int sl; string du = "", t[11], c = ""; t[0] = ""; for(int i = 1; i <= 10; ++i) t[i] = congsl(t[i-1],b); for(int i = 0; i < a.length(); ++i) { du += a[i]; sl = 0; while(ss(du,t[sl])) sl++; c += char(sl-1+48); du = trusl(du,t[sl-1]); } while(c[0] == '0' and c.length() > 1) c.erase(0,1); return c; } string mod(string a, string b) { int sl; string du = "", t[11], c = ""; t[0] = ""; for(int i = 1; i <= 10; ++i) t[i] = congsl(t[i-1],b); for(int i = 0; i < a.length(); ++i) { du += a[i]; sl = 0; while(ss(du,t[sl])) sl++; c += char(sl-1+48); du = trusl(du,t[sl-1]); } while(c[0] == '0' and c.length() > 1) c.erase(0,1); return du; } void chiaslsn(string a, long long b) { string c = ""; long long du = 0; for(int i = 0; i < a.length(); ++i) { du = du * 10 + a[i] - 48; c += char(du / b + 48); du %= b; } while(c[0] == '0' and c.length() > 1) c.erase(0, 1); cout << c << endl << du; } int main() { iosbase::syncwith_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("congsl.INP","r",stdin); //freopen("congsl.OUT","w",stdout); string a, b; cin >> a >> b; cout << "a + b = " << congsl(a,b) << endl; if(ss(a,b)) cout << "a - b = " << trusl(a,b) << endl; else cout << "a - b = " << '-' << trusl(b,a) << endl; cout << "a * b = " << nhanslsl(a,b) << endl; cout << "a / b = " << chiaslsl(a,b) << endl; cout << "a % b = " << mod(a, b); return 0; }