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 <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define r0 return 0
using namespace std;
const int N = 5 * 1e6 + 5, M = 501, MOD = 998244353, mod = 1e9 + 7;
string s;
int tr[4 * N],a[N],n,m,k,l,q,x,r,tr2[4 * N],b[N];
int bin[N];
void precalc () {
bin[0] = 1;
for (int i = 1; i <= 1e6; i++) {
bin[i] = bin[i - 1] * 2 % mod;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
precalc();
cin >> n >> k;
int i = 0; k = k - 1;
// cout << k << " " << k % 2 << endl;
while (k > 0) {
b[i] = k % 2;
k = k / 2;
i++;
}
while (i < n - 1) {
b[i] = 0;
i++;
}
// for (int j = 0; j <= i; j++) {
// cout << b[j];
// }
reverse (b, b + n);
cout << endl;
int x = 0;
for (int i = 0; i <= n - 1; i++) {
if (b[i] == 0) continue;
x = (x + bin[i]) % mod;
// cout << x << " " << i << " " << bin[i] << endl;
}
cout << x + 1 << endl;
return 0;
}
// 5 10 ... 10 = 0 1 0 1 0; 9 = 0 1 0 0 1
// b[] = 1 0 0 1 0 => 0 1 0 0 1;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |