Submission #581100

# Submission time Handle Problem Language Result Execution time Memory
581100 2022-06-22T09:13:34 Z Banan Rack (eJOI19_rack) C++17
100 / 100
1 ms 320 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define double long double
#define endl '\n'
#define sz size
#define pb push_back
#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
int const INF = LONG_LONG_MAX;
int const mod = 1e9 + 7;

int n, k;

int bp(int x)
{
    int res=1, a=2;
    while(x)
    {
        if(x&1)res*=a;
        res%=mod;
        a*=a;
        a%=mod;
        x>>=1;
    }
    return res%mod;
}

void solve()
{
    cin>>n>>k;
    int ans=0;
    int val=bp(n-1), inv=bp(mod-2);
    while(k>1)
    {
        if(k%2==0){ans+=val;}
        ans%=mod;
        k=(k+1)/2;
        val=(val*inv)%mod;
    }
    if(k==1) ans++;
    ans%=mod;
    cout<<ans<<endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct