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>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll mod = 1000000007;
vll po2;
ll pow2(ll x) {
if (x >= po2.size()) {
if (x & 1) {
po2[x] = (2 * pow2(x - 1)) % mod;
} else {
po2[x] = (pow2(x / 2) * pow2(x / 2)) % mod;
}
}
return po2[x];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
k -= 1;
po2.push_back(1);
// for a structure with n levels, on which hook should the k'th coat hang
// consinder hanging coats one by one. for each rack, it alternates whether it should be hung to the left or right, always starting with the left
// so we check the bitrepresentation of k
// 0000, 1000, 0100, 1100, 0010, 1010, 0110, 1110, 0001, 1001, 0101, 1101, 0011, 1011, 0111, 1111
// so the answer is k reversed mod 2 ^ n...
ll answ = 0;
for (int i = 0; i < 63; i++) {
if ((k >> i) & 1) {
answ += pow2(n - 1 - i);
answ %= mod;
}
}
cout << answ + 1 << endl;
return 0;
}
Compilation message (stderr)
rack.cpp: In function 'll pow2(ll)':
rack.cpp:20:11: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (x >= po2.size()) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |