Submission #19058

# Submission time Handle Problem Language Result Execution time Memory
19058 2016-02-17T22:24:46 Z kriii Ω (kriii4_P3) C++14
0 / 100
0 ms 1084 KB
#include <stdio.h>

const long long mod = 1000000007;

long long fpow(long long a, long long p)
{
	a = (a % mod + mod) % mod;
	p = (p % (mod - 1) + mod - 1) % (mod - 1);
	long long r = 1;
	while (p){
		if (p & 1) r = r * a % mod;
		a = a * a % mod;
		p >>= 1;
	}
	return r;
}

int main()
{	
	int P,Q,N,K; 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 (Q * 2 == P) printf ("%lld\n",K*fpow(N,-1));
	else{
		long long u = Q * fpow(P-Q,-1) % mod;
		long long ans = (1 - fpow(u,K)) * fpow(1-fpow(u,N),-1);
		printf ("%lld\n",(ans%mod+mod)%mod);
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
11 Correct 0 ms 1084 KB Output is correct
12 Correct 0 ms 1084 KB Output is correct
13 Correct 0 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Incorrect 0 ms 1084 KB Output isn't correct
18 Halted 0 ms 0 KB -