# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464529 | 2021-08-13T11:02:57 Z | Itamar | Rack (eJOI19_rack) | C++14 | 0 ms | 0 KB |
#include <iostream> using namespace std; #include <algorithm> #include <vector> long long y = pow(10, 9) + 7; long long po(long long a, long long b) { if (b == 0) { return 1; } vector<bool> vec; long long c = a; while (b > 1) { if (b % 2 == 1) { vec.push_back(0); b = b - 1; } else { vec.push_back(1); b = b / 2; } } reverse(vec.begin(), vec.end()); int vec_size = vec.size(); for (int i = 0; i < vec_size; i++) { if (vec[i] == 0) { a = (a * c) % y; } else { a = (a * a) % y; } return a; } } long long fun(long long n, long long k) { if (k == 1) { return 1; } if (k % 2 == 0) { long long x = fun(n - 1, k / 2); long long b = po(2, n - 1); return (x + b) % y; } else { long long x = fun(n - 1, k / 2 + 1); return x% y; } } int main() { long long n, k; cin >> n; cin >> k; cout << fun(n, k); }