제출 #1195347

#제출 시각아이디문제언어결과실행 시간메모리
1195347JohanRack (eJOI19_rack)C++20
100 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
  
const int MAX = 3e5 + 6;
const int LOG = 26;
const int inf = 1e18;
const int mod = 1e9 + 7;
const int block = 320;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int pow(int x){
	int cnt = 0;
	while(x > 1){
		x /= 2;
		cnt++;
	}
	return cnt;
}
int binpow(int a, int b){
	int res = 1;
	while(b != 0){
		if(b % 2 == 1){
			res *= a;
			res %= mod;
		}
		a *= a;
		a %= mod;
		b /= 2;
	}
	return res;
}
void _(){
	int n, k;
	cin >> n >> k;
	vector < int > cur;
	for(int i = 0; i <= 60; i++)
		cur.push_back(pow(2, i));
	int tot = 0;
	while(k > 1){
		int ans;
		for(int i = 0; i <= 60; i++){
			if(cur[i] >= k)	break;
			ans = cur[i];
		}
		int power = pow(ans);
//		cout << tot << '-';
		int x = binpow(2, n - power - 1) % mod;
//		cout << n - power - 1 <<  ' ' << x << endl;
		tot = (tot + x) % mod;
		k -= ans;
	}
	cout << (tot + 1) % mod << endl;
}
 
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
//	cin >> t;
	while(t--)  _();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...