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;
#define MOD 1000000007
long long int q(long long int a,long long b)
{
long long pr=1;
while(b!=0)
{
if(b%2==1)
pr=(pr*a)%MOD;
b/=2;
a=(a*a)%MOD;
}
return pr;
}
long long int rack(long long int n,long long int k)
{
long long int l(0),r(q(2,n)%MOD);
map<long long int,int>freq;
while(k)
{
if(freq[k]>1&&k==1)
return (l%MOD);
long long int mid=((l+r)%MOD/2)%MOD;
if(k%2)
r=mid-1;
else
l=mid+1;
int fr(k%2);
k/=2;
k+=fr;
++freq[k];
}
return l%MOD;
}
int main()
{
//EWEX
//SXSN
//WSEX
long long int n,k;
cin>>n>>k;
cout<<rack(n,k);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |