# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165212 | coloredrabbit | Ω (kriii4_P3) | C++17 | 2 ms | 376 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 <iostream>
using ll = long long;
const ll MOD = 1e9 + 7;
ll _pow(ll a, int n) {
if (n <= 1) return n % 2 ? a : 1;
ll h = _pow(a, n >> 1);
return (((h * h) % MOD) * (n % 2 ? a : 1)) % MOD;
}
ll rev(ll x) { return _pow(x % MOD, MOD - 2); }
int main() {
int P, Q, N, K;
ll v, ans = 0, A, B, g, X;
scanf("%d%d%d%d", &P, &Q, &N, &K);
if (K == 0 || Q == P) puts("0");
else if (K == N || Q == 0) puts("1");
else {
if (2 * Q == P)
ans = (K * rev(N)) % MOD;
else {
v = (Q * rev(P - Q)) % MOD;
ans = (((1 - _pow(v, K) + MOD) % MOD) * (rev(1 - _pow(v, N) + MOD) % MOD)) % MOD;
}
std::cout << ans;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |