Submission #764496

#TimeUsernameProblemLanguageResultExecution timeMemory
764496TrunktyOdd-even (IZhO11_oddeven)C++14
0 / 100
3 ms332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll struct bigint{ vector<int> v={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; }; int mod = 1e9; bigint add(bigint a, bigint b){ bigint c; for(int i=0;i<=30;i++){ c.v[i] = a.v[i]+b.v[i]; if(c.v[i]>mod){ c.v[i] -= mod; c.v[i+1]++; } } return c; } bigint sub(bigint a, bigint b){ bigint c; for(int i=0;i<=30;i++){ c.v[i] = a.v[i]-b.v[i]; if(c.v[i]<0){ c.v[i] += mod; a.v[i+1]--; } } return c; } bigint mult(bigint a, bigint b){ bigint c; for(int i=0;i<=30;i++){ for(int j=0;j<=30;j++){ if(i+j<=30){ c.v[i+j] += a.v[i]*b.v[j]; c.v[i+j+1] += c.v[i+j]/mod; c.v[i+j] %= mod; } } } return c; } bool bigeq(bigint a, bigint b){ for(int i=30;i>=0;i--){ if(a.v[i]>b.v[i]){ return true; } else if(a.v[i]<b.v[i]){ return false; } } return true; } string s; bigint n,one,two; signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); one.v[0] = 1; two.v[0] = 2; cin >> s; reverse(s.begin(),s.end()); for(int i=s.length()-1;i>=0;i--){ n.v[i/9] *= 10LL; n.v[i/9] += s[i]-'0'; } n = mult(n,two); bigint tosub; for(int j=15;j>=0;j--){ int low=0,high=mod-1; while(low!=high){ int mid = (low+high+1)/2; tosub.v[j] = mid; if(bigeq(mult(tosub,add(tosub,one)),n)){ high = mid-1; } else{ low = mid; } } tosub.v[j] = low; } tosub = add(tosub,one); n = sub(n,tosub); for(int i=30;i>=0;i--){ if(n.v[i]>0){ cout << n.v[i]; } } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...