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 int long long
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
using namespace std;
const int mod=1e9+7;
int MOD(int x){
return ((x+mod)%mod);
}
int fast_pow(int x, int p){
if(p==1) return x;
if(p==0) return 1;
if(p%2==0) return MOD(MOD(fast_pow(x,p/2))*MOD(fast_pow(x,p/2)));
else return MOD(MOD(fast_pow(x,p-1))*x);
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n,k; cin >> n>>k;
k--;
int sum=1;
for (int i = 1; i <= n; i++)
{
if((1LL<<(i-1LL))>k) break;
if(k&(1LL<<(i-1LL))) sum=MOD(sum+MOD(fast_pow(2LL, (n-i))));
}
cout << sum << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |