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>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ppb pop_back()
const int N = (int)1e5 + 5;
const ll mod = (int)1e9 + 7;
const ll inf = (1e9) + 100;
ll binpow(ll a, ll n) {
if (n < 0) return 0;
if (n == 0) return 1;
if (n == 1) return a % mod;
int v = binpow(a, n / 2);
if (n & 1) return (((v * v) % mod) * a) % mod;
return (v * v) % mod;
}
ll add(ll a, ll b) {
return (((a + b) % mod) + mod) % mod;
}
void solve() {
ll n, k;
cin >> n >> k;
ll ans = 1;
ll p = binpow(2, n - 1);
ll l = n - 1;
while (k > 1) {
if (k & 1) {
k = (k / 2) + 1;
} else {
k /= 2;
ans = add(ans, p);
}
l--;
p = binpow(2, l);
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T = 1;
//cin >> T;
while (T--) solve();
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |