| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 490946 | kawaii | Multiply (CEOI17_mul) | C++17 | 70 ms | 131076 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
string n, m;
int a, b;
string add(string a, string b){
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
a.push_back('0'); b.push_back('0');
while(a.size() > b.size()) b.push_back('0');
while(a.size() < b.size()) a.push_back('0');
int cnt = 0, du = 0;
string res = "";
for(int i = 0; i < a.size(); i++){
cnt = a[i] + b[i] - 96 + du;
du = cnt / 10;
res.push_back(char(cnt % 10 + 48));
}
while(res.back() == '0') res.pop_back();
reverse(res.begin(), res.end());
return res;
}
string chia(string a){
string res = "";
int p = 0;
for(int i = 0; i < a.size(); i++){
p = p * 10 + a[i] - 48;
if(p >= 2){
res.push_back(char(p / 2 + 48));
p %= 2;
}
else res.push_back('0');
}
reverse(res.begin(), res.end());
while(res.back() == '0') res.pop_back();
reverse(res.begin(), res.end());
return res;
}
string nhan(string a, string b){
if(b == "1") return a;
string ans = nhan(a, chia(b));
//cout << a <<" "<< chia(b) << "\n";
if(b.back() % 2 == 0) return add(ans, ans);
else return add(add(ans, ans), a);
}
void solve(){
cout << nhan(n, m);
}
signed main(){
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
cin >> a >> b >> n >> m;
solve();
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
