# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
288544 | Benmath | Rack (eJOI19_rack) | C++14 | 0 ms | 256 KiB |
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<bits/stdc++.h>
using namespace std;
long long int solve(long long int step[],long long int b,long long int n,long long int mod){
long long int step1=1;
long long int x,y;
long long int b1;
if(b%2==0){
y=(b-2)/2;
}else{
y=(b-1)/2;
}
if(y==0 or b==0){
return 1;
}
int mi=0;
for(int i=1;i<=n;i++){
if(i!=1){
step1*=2;
mi++;
}
if((y-step1)<step1){
b1=y-step1;
break;
}
}
b1=b1%mod;
if(b%2==0){
return ( solve(step,b1,n-2-mi,mod)*step[n-2-mi]+step[n-1])%mod;
}else{
return (solve(step,b1,n-2-mi,mod)*step[n-2-mi])%mod;
}
}
int main(){
int n;
cin>>n;
long long int k;
cin>>k;
long long int mod=1000000007;
k=k%mod;
long long int step[n+1];
step[0]=1;
for(int i=1;i<=n;i++){
step[i]=(step[i-1]*2)%mod;
}
if(k==1){
cout<<1;
}else if(k==2){
cout<<step[n-1]+1;
}else{
cout<<solve(step,k,n,mod)+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... |