Submission #1112009

#TimeUsernameProblemLanguageResultExecution timeMemory
1112009vjudge1Rack (eJOI19_rack)C++17
100 / 100
1 ms504 KiB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define nmod(a, b) (((a%b)+b)%b) // stands for [n]atural [mod], as in "will always return a natural number", should be used in case of negative
#define a2b(a, b) (a << b) // a*2^b
#define bit(a, b) ((a >> b) & 1) // bth bit from the right, starts at zero
using namespace std;
template<class T> using vec = vector<T>;

const int INFTY = (1LL << 63) - 1;
const int NNFTY = 1LL << 63;
const int mod = 1'000'000'007;

int csp(int a, int k) { // a's closest smaller power of k
    int n = 1;
    while (a > 1) n *= k, a /= k;
    return n;
}

int binpow(int x, int y) {
    if (y < 0) return binpow(x, mod - 1 + y); // allows for binpow(x, -1)
    if (y == 0 || x == 1) return 1;
    if (y == 1) return x%mod;
    if (y % 2 == 0) return binpow((x*x)%mod, y/2);
    return (x*binpow(x, y - 1))%mod;
}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, k, ans = 0; cin >> n >> k;
    k--;
    while (k > 0) {
        int m = csp(k, 2);
        ans += (binpow(2, n) * binpow((2*m)%mod, -1))%mod;
        k -= m;
    }
    cout << (ans + 1) % mod;
}

Compilation message (stderr)

rack.cpp:10:31: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
   10 | const int INFTY = (1LL << 63) - 1;
      |                   ~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...