#include <iostream>
#include <vector>
using namespace std;
#define int long long
const int N = (1<<20) + 1;
int tp[N];
int mod = 1e9 + 7;
void solve(int n,int k){
bool right = true;
int ans = 0;
for (int i=1;i<=n;i++){
bool last = 1&k;
k >>= 1;
if (right and last)
right = 0;
else if (right)
ans += tp[n - i];
else if (!right and last)
ans += tp[n - i];
}
cout<<(ans + !right)%mod<<endl;
}
signed main(){
tp[0] = 1;
for (int i=1;i<N;i++)
tp[i] = tp[i-1] * 2 % mod;
int n,k;
cin>>n>>k;
if (k==tp[n])
cout<<tp[n]<<endl;
else
solve(n,k);
return 0;
for (int i=1;i<=8;i++)
solve(3,i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8536 KB |
Output is correct |
2 |
Correct |
7 ms |
8540 KB |
Output is correct |
3 |
Correct |
6 ms |
8580 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
6 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8536 KB |
Output is correct |
2 |
Correct |
7 ms |
8540 KB |
Output is correct |
3 |
Correct |
6 ms |
8580 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
6 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
6 ms |
8540 KB |
Output is correct |
8 |
Correct |
6 ms |
8540 KB |
Output is correct |
9 |
Correct |
6 ms |
8556 KB |
Output is correct |
10 |
Correct |
6 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8536 KB |
Output is correct |
2 |
Correct |
7 ms |
8540 KB |
Output is correct |
3 |
Correct |
6 ms |
8580 KB |
Output is correct |
4 |
Correct |
6 ms |
8540 KB |
Output is correct |
5 |
Correct |
6 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
6 ms |
8540 KB |
Output is correct |
8 |
Correct |
6 ms |
8540 KB |
Output is correct |
9 |
Correct |
6 ms |
8556 KB |
Output is correct |
10 |
Correct |
6 ms |
8540 KB |
Output is correct |
11 |
Correct |
6 ms |
8540 KB |
Output is correct |
12 |
Correct |
6 ms |
8836 KB |
Output is correct |
13 |
Correct |
6 ms |
8644 KB |
Output is correct |
14 |
Correct |
7 ms |
8540 KB |
Output is correct |
15 |
Correct |
7 ms |
8540 KB |
Output is correct |