#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int am = 0;
ll binpow(ll a, ll b){
ll res = 1;
if (b == -1){
return 0;
}
while (b != 0){
if (b % 2 == 0){
b /= 2;
a *= a;
if (a >= mod){
am++;
}
a %= mod;
}
else{
b -= 1;
res *= a;
if (res >= mod){
am++;
}
res %= mod;
}
}
return res;
}
ll f(ll n, ll k, ll va){
ll val = 0;
if (n == 0){
return val;
}
am = 0;
ll po = binpow(2, n - 1);
if ((am == 0 && k >= po)){
val += binpow(2, va);
return (val + f(n - 1, k - po, va + 1)) % mod;
}
else if ((am == 1 && k >= po * mod)){
val += binpow(2, va);
return (val + f(n - 1, k - po * mod, va + 1)) % mod;
}
return (val + f(n - 1, k, va + 1)) % mod;
}
int main(){
int n, k;
cin>>n>>k;
k--;
cout<<(f(n, k, 0) + 1) % mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |