#include <bits/stdc++.h>
#define N 1000005
#define int long long
using namespace std;
const int mod = 1e9+7;
int pw(int b){
int ret = 1;
for(int i=0;i<b;i++){
ret = min((int)2e18,ret*2);
}
return ret;
}
int pw2(int b){
int ret = 1;
for(int i=0;i<b;i++){
ret = ret*2%mod;
}
return ret;
}
void solve(){
int n,k;
cin >> n >> k;
int ans = 0;
if(k > pw(n-1)){
assert(0);
ans++;
k -= pw(n-1);
}
int cnt = 1;
if(k <= 2){
cout << (1 + ans + (k-1)*pw2(n-1))%mod << "\n";
return;
}
k -= 2;
for(int i=2;;i++){
cnt*=2;
if(k <= cnt){
cout << (1 + ans + pw2(n-i) + (k-1)/2*pw2(n-i+1) + (k%2==0) *pw2(n-1))%mod << "\n";
break;
}
k -= cnt;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |