# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464531 | Itamar | Rack (eJOI19_rack) | C++14 | 1 ms | 204 KiB |
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>
using namespace std;
#include <algorithm>
#include <vector>
long long y = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 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);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |