Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: exoworldgd
Problemset: I.Quick Math
Language: cpp
Time: 0.015 second
Submitted On: 2025-08-22 23:45:50
#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define exoworldgd cin.tie(0)->sync_with_stdio(0),cout.tie(0)
#define int long long
using namespace std;
const int inf = LLONG_MAX, mod = 1e9+7;
string add(string a, string b) {
string res;
int carry = 0;
if (a.length() < b.length()) swap(a, b);
b.insert(0, a.length() - b.length(), '0');
for (int i = a.length() - 1; i >= 0; i--) {
int sum = (a[i] - '0') + (b[i] - '0') + carry;
carry = sum / 10, res += (sum % 10) + '0';
}
if (carry) res += carry + '0';
reverse(res.begin(),res.end());
return res;
}
string mult(string a, string b) {
string res = "0";
if (a == "0" || b == "0") return "0";
if (a.length() < b.length()) swap(a,b);
for (int i = b.length() - 1; i >= 0; i--) {
string temp = "";
int carry = 0, db = b[i]-'0';
for (int k = 0; k < b.length()-1-i; k++) temp += "0";
for (int j = a.length()-1; j >= 0; j--) {
int prod = (a[j]-'0')*db+carry;
carry = prod/10, temp += (prod%10) + '0';
}
if (carry) temp += carry + '0';
reverse(temp.begin(),temp.end()), res = add(res,temp);
}
return res;
}
signed main(void) {
exoworldgd;
string a,b;
cin >>a >> b;
cout << mult(a,b);
}