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;
#define ll long long
#define MOD 1000000007
#define MAXN 100005
typedef pair<int, int> pii;
ll fast(ll base, ll exp){
if(exp==0) return 1%MOD;
ll u = fast(base,exp/2);
u=(u*u)%MOD;
if (exp%2==1) u=(u*base)%MOD;
return u;
}
ll solve(ll n, ll k){
if(n==1&&k==1)return 1%MOD;
if(n==1&&k==2)return 2%MOD;
ll ans = fast(2,n-1);
if(k%2==0)return (solve(n-1,k/2)+ans)%MOD;
else return solve(n-1,(k+1)/2)%MOD;
}
int main(){
ll n,k,ans;
cin>>n>>k;
ans=solve(n,k)%MOD;
if(ans<0)ans+=MOD;
cout<<ans<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |