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 <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll pw(ll a, ll m){
if(!m)
return 1;
a %= MOD;
if(m % 2)
return (a * pw(a, m - 1)) % MOD;
return pw(a * a, m / 2);
}
signed main(){
ll n, k;
cin >> n >> k;
--k;
ll ans = 0;
ll r2 = pw(2, MOD - 2);
ll pw2 = pw(2, n - 1);
for(ll i = 0; i < min(n, 63ll); ++i){
if(k & (1ll << i)){
ans += pw2;
ans %= MOD;
}
pw2 = (pw2 * r2) % MOD;
}
cout << ans + 1 << endl;
//if(n <= 20){
//vector<ll> a = {1};
//for(int sz = 1, pw = (1 << (n - 1)); sz <= k; sz *= 2, pw /= 2){
//for(int i = 0; i < sz; ++i){
//a.push_back(a[i] + pw);
//}
//}
//cout << a[k] << endl;
//}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |