Submission #893092

#TimeUsernameProblemLanguageResultExecution timeMemory
893092preskoOdd-even (IZhO11_oddeven)C++14
0 / 100
0 ms348 KiB
#include<iostream> #include<bits/stdc++.h> using namespace std; long long getseg(long long n) { long long ans=0; long long l=1,r=n;//r while(r-l>1) { long long mid=(l+r)>>1; long long st,en=mid*(mid+1); en>>=1; st=en-mid+1; if(n<st)r=mid; else if(n>st)l=mid; else {ans=mid;break;} } if(ans>0)return ans; long long bl,br=l*(l+1); br>>=1; bl=br-l+1; if(bl<=n && n<=br)return l; else return r; } int main() { long long n; ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; long long seg=getseg(n); long long fin=seg*seg,en=seg*(seg+1); en>>=1; long long diff=en-n,ans=0; diff<<=1; ans=fin-diff; cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...