Submission #319149

#TimeUsernameProblemLanguageResultExecution timeMemory
319149sofapudenOdd-even (IZhO11_oddeven)C++14
0 / 100
1022 ms504 KiB
#include <bits/stdc++.h> using namespace std; string add(string a, string b){ string c; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); while(a.size() < b.size()){ a+='0'; } while(b.size() < a.size()){ b+='0'; } int last = 0; for(int i = 0; i < (int)a.size(); ++i){ int cur = a[i]+b[i]-2*'0' + last; last = cur/10; c+=(char)('0'+cur%10); } if(last){ c+=(char)('0'+last); } reverse(c.begin(),c.end()); return c; } string subs(string a, string b){ string c; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); while(b.size() < a.size()){ b+='0'; } int last = 0; for(int i = 0; i < (int)a.size(); ++i){ int cur = a[i]-b[i] + last; last = (cur-10)/10; c+=(char)('0'+((cur+10)%10)); } while(c.back() == '0')c.pop_back(); reverse(c.begin(),c.end()); return c; } bool gre(string a, string b){ if(a.size() > b.size()){ return true; } if(b.size() > a.size()){ return false; } return a >= b; } int main(){ string a; cin >> a; string cn = "1"; string cur = "1"; while(!gre(cur,a)){ cn = add(cn,"1"); cur = add(cur,cn); } cout << subs(add(a,a),cn); }
#Verdict Execution timeMemoryGrader output
Fetching results...