# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
893092 | presko | Odd-even (IZhO11_oddeven) | C++14 | 0 ms | 348 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<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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |