fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7.  
  8. const int INF = 1e9;
  9. const ll LINF = 1e18;
  10.  
  11. struct BigInt {
  12. static const int BASE = 1e9;
  13. static const int B = 9;
  14.  
  15. vector<int> a;
  16.  
  17. BigInt() {}
  18.  
  19. BigInt(ll x) {
  20. for (; x > 0; x /= BASE) {
  21. a.push_back(x % BASE);
  22. }
  23. }
  24.  
  25. BigInt(const string &s) {
  26. for (int i = (int)s.size() - 1; i >= 0; i -= B) {
  27. int beg = max(0, i - B + 1);
  28. int len = i - beg + 1;
  29. int block = stoi(s.substr(beg, len));
  30. a.push_back(block);
  31. }
  32. trim();
  33. }
  34.  
  35. void trim() {
  36. while (!a.empty() && a.back() == 0) {
  37. a.pop_back();
  38. }
  39. }
  40.  
  41. bool isZero() {
  42. return (a.empty());
  43. }
  44.  
  45. BigInt operator*=(const BigInt &other) {
  46. int n = a.size(), m = other.a.size();
  47. vector<int> c(n + m, 0);
  48. for (int i = 0; i < n; i++) {
  49. int carry = 0;
  50. for (int j = 0; j < m || carry; j++) {
  51. ll cur = c[i + j] + 1ll * a[i] * (j < m ? other.a[j] : 0) + carry;
  52. c[i + j] = cur % BASE;
  53. carry = cur / BASE;
  54. }
  55. }
  56. swap(a, c);
  57. trim();
  58. return *this;
  59. }
  60.  
  61. BigInt operator*(const BigInt &other) const {
  62. return BigInt(*this) *= other;
  63. }
  64.  
  65. friend istream& operator>>(istream &in, BigInt &num) {
  66. string s;
  67. in >> s;
  68. num = BigInt(s);
  69. return in;
  70. }
  71.  
  72. friend ostream& operator<<(ostream &out, const BigInt &num) {
  73. out << (num.a.empty() ? 0 : num.a.back());
  74. for (int i = (int)num.a.size() - 2; i >= 0; i--) {
  75. out << setw(B) << setfill('0') << num.a[i];
  76. }
  77. return out;
  78. }
  79. };
  80.  
  81. int main() {
  82. ios::sync_with_stdio(false);
  83. cin.tie(nullptr);
  84. int t; cin >> t;
  85.  
  86. while (t--) {
  87. BigInt a, b;
  88. cin >> a >> b;
  89. cout << a * b << '\n';
  90. }
  91. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
4 2
123 43
324 342
0 12
9999 12345
stdout
8
5289
110808
0
123437655