Submission #164895

# Submission time Handle Problem Language Result Execution time Memory
164895 2019-11-24T03:55:33 Z coloredrabbit Ω (kriii4_P3) C++17
0 / 100
2 ms 504 KB
#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 rev(ll x) { return _pow(x, MOD - 2); }
int main() {
	int P, Q, N, K, i;
	ll v, ans = 0;
	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 {
		v = Q * rev(P - Q);
		ans = (1 - _pow(v, K) + MOD) * rev(1 - _pow(v, N) + MOD) % MOD;
		if(2*Q == P)
			ans = (ans + K * rev(N)) % MOD;
		printf("%lld", ans);
	}
	
	return 0;
}

Compilation message

P3.cpp: In function 'int main()':
P3.cpp:11:18: warning: unused variable 'i' [-Wunused-variable]
  int P, Q, N, K, i;
                  ^
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 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -