Submission #164965

#TimeUsernameProblemLanguageResultExecution timeMemory
164965coloredrabbitΩ (kriii4_P3)C++17
0 / 100
2 ms376 KiB
#include <cstdio> const int MOD = 1e9+7; using ll = long long; 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 gcd(ll p, ll q) { return !q ? p : gcd(q, p % q); } ll rev(ll x) { return _pow(x, MOD - 2); } int main() { int P, Q, N, K; ll v, ans = 0, A, B, g; 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); //ans = ((1 - _pow(v, K) + MOD) % MOD) * (rev(1 - _pow(v, N) + MOD) % MOD) % MOD; A = (_pow(P - Q, N) - _pow(P - Q, N - K) * _pow(Q, K) % MOD + MOD) % MOD; B = (_pow(P - Q, N) - _pow(Q, N) + MOD) % MOD; g = gcd(A, B); A /= g, B /= g; ans = A * rev(B) % MOD; } printf("%lld", ans); } return 0; }

Compilation message (stderr)

P3.cpp: In function 'int main()':
P3.cpp:13:5: warning: variable 'v' set but not used [-Wunused-but-set-variable]
  ll v, ans = 0, A, B, g;
     ^
P3.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &P, &Q, &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...