Submission #601182

#TimeUsernameProblemLanguageResultExecution timeMemory
601182FidanRack (eJOI19_rack)C++17
100 / 100
17 ms15540 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=(2e5)+10;
const ll num=(1e9)+7;

vector<ll> p(60, 1);
void power(){
	for(ll i=1; i<60; i++){
		p[i]=p[i-1]*2;
	}
}

ll solve(ll n, ll k){
	if(k==1) return 1;
	if(n==1) return k;
	if(n>=61){
		return (2*solve(n-1, k)-1)%num;
	}
	else{
		if(k>p[n-1]){
			return (2*solve(n-1, k-p[n-1]))%num;
		}
		else{
			return (2*solve(n-1, k)-1)%num;
		}
	}
}
		
int main(){
	ll n, k;
	cin>>n>>k;
	power();
	cout<<solve(n, k);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...