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>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef string str;
const ll mod=1e9+7;
ll powr(ll a,ll b){
if(b==0) return 1;
ll ret=powr(a,b/2);
ret*=ret;
ret%=mod;
if(b&1) ret*=a;
ret%=mod;
return ret;
}
int main()
{
ios;
ll n,k;
cin>>n>>k;
ll l=1;
ll r=powr(2,n);
ll vel=n;
while(vel){
ll mid=l+powr(2,vel-1)-1;
mid=(mid%mod+mod)%mod;
//cout<<l<<" "<<r<<" "<<k<<"\n";
if(k&1){
r=mid;
k=(k-1)/2+1;
}else{
l=mid+1;
l%=mod;
k/=2;
}
vel--;
}
cout<<(l%mod+mod)%mod;
return 0;
}
Compilation message (stderr)
rack.cpp: In function 'int main()':
rack.cpp:44:8: warning: variable 'r' set but not used [-Wunused-but-set-variable]
44 | ll r=powr(2,n);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |