# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1211246 | nguyn | Rack (eJOI19_rack) | C++20 | 0 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int n, k;
int pw[N];
void add(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> k;
// if (n <= 20) {
// vector<int> cur;
// cur.pb(1);
// for (int i = (1 << (n - 1)); i >= 1; i >>= 1) {
// int sz = cur.size();
// for (int j = 0; j < sz; j++) {
// cur.pb(cur[j] + i);
// }
// }
// // for (int i : cur) {
// // cout << i << ' ';
// // }
// cout << cur[k - 1] << '\n';
// return 0;
// }
pw[0] = 1;
for (int i = 1; i <= n; i++) {
pw[i] = pw[i - 1] + pw[i - 1];
if (pw[i] >= mod) pw[i] -= mod;
}
int res = 0;
for (int i = min(n, 60ll); i >= 0; i--) {
if (k > (1 << i)) {
int t = i + 1;
// cout << t << ' ' << pw[n - t] << '\n';
add(res, pw[n - t]);
k -= (1 << i);
}
}
cout << res + 1;
}
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... |