이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |