Submission #675720

#TimeUsernameProblemLanguageResultExecution timeMemory
675720AlmaRack (eJOI19_rack)C++17
0 / 100
1096 ms212 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; ll MOD = 1e9+7; ll calcMODpow(int b, int p) { if (p == 0) return 1; ll x = calcMODpow(b, p/2); if (p % 2 == 1) { return (((x*x) % MOD)*b) % MOD; } else { return (x*x) % MOD; } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; ll pos = 1, add = n; bool inv = false; int i = 0; while (i < n) { if ((1 << i) > k) { break; } add--; if (inv == false) { if ((k & (1 << i))) { inv = true; } else { pos += calcMODpow(2, add); pos %= MOD; } } else { if ((k & (1 << i))) { pos += calcMODpow(2, add); pos %= MOD; } else { inv = true; } } i++; } while (i < n) { add--; if (inv) { pos += calcMODpow(2, add); pos %= MOD; } } cout << pos << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...