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;
const int64_t MOD = 1000000007;
int64_t fast_pow(int64_t x, int64_t y) {
x %= MOD;
if (x == 0) {
return 0;
}
int64_t res = 1;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % MOD;
}
y >>= 1;
x = (x * x) % MOD;
}
return res;
}
int64_t solve(int64_t n, int64_t k) {
if (n == 0) {
if (k != 0) {
abort();
}
return 1;
}
if (k % 2 == 0) {
return solve(n - 1, k / 2);
} else {
int64_t k2 = 0;
if (k > 1) {
k2 = k / 2;
}
return (fast_pow(2, n - 1) + solve(n - 1, k2)) % MOD;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int64_t n, k;
cin >> n >> k;
cout << solve(n, k - 1) << 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... |