Submission #165213

# Submission time Handle Problem Language Result Execution time Memory
165213 2019-11-26T03:25:16 Z coloredrabbit Ω (kriii4_P3) C++17
100 / 100
7 ms 504 KB
#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) puts("0");
	else if (K == N) puts("1");
	else if (Q == 0) puts("1");	
	else if (Q == P) puts("0");
	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

P3.cpp: In function 'int main()':
P3.cpp:12:17: warning: unused variable 'A' [-Wunused-variable]
  ll v, ans = 0, A, B, g, X;
                 ^
P3.cpp:12:20: warning: unused variable 'B' [-Wunused-variable]
  ll v, ans = 0, A, B, g, X;
                    ^
P3.cpp:12:23: warning: unused variable 'g' [-Wunused-variable]
  ll v, ans = 0, A, B, g, X;
                       ^
P3.cpp:12:26: warning: unused variable 'X' [-Wunused-variable]
  ll v, ans = 0, A, B, g, X;
                          ^
P3.cpp:13: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 time Memory Grader output
1 Correct 7 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 396 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 3 ms 256 KB Output is correct