Submission #19408

# Submission time Handle Problem Language Result Execution time Memory
19408 2016-02-24T11:27:00 Z tonyjjw Ω (kriii4_P3) C++14
100 / 100
0 ms 1720 KB
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <limits.h>
#include <locale.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
#include <unordered_set>
#include <unordered_map>

#pragma warning(disable:4996)
using namespace std;

#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <ldb, ldb> pdd;

int IT_MAX = 131072;
const ll MOD = 1000000007;
const int INF = 1034567891;
const ll LL_INF = 2234567890123456789ll;
const db PI = 3.141592653589793238;
const ldb ERR = 1E-10;

ll mul_inv(ll a, ll b)
{
	ll b0 = b, t, q;
	ll x0 = 0, x1 = 1;
	if (b == 1) return 1;
	while (a > 1) {
		q = a / b;
		t = b, b = a % b, a = t;
		t = x0, x0 = x1 - q * x0, x1 = t;
	}
	if (x1 < 0) x1 += b0;
	return x1;
}

int main() {
	int P, Q, N, K, i;
	scanf("%d %d %d %d", &P, &Q, &N, &K);

	if (N == K) return !printf("1\n");
	if (K == 0) return !printf("0\n");
	if (Q == 0) return !printf("1\n");
	if (Q == P) return !printf("0\n");
	if (Q * 2 == P) {
		ll ans = K;
		ans = (ans * mul_inv(N, MOD)) % MOD;
		return !printf("%lld\n", ans);
	}

	ll m = (Q * mul_inv((P-Q), MOD)) % MOD;
	
	ll t1 = 1;
	for (i = 1; i <= K; i++) t1 = (t1*m) % MOD;
	t1 = (1 - t1 + MOD) % MOD;

	ll t2 = 1;
	for (i = 1; i <= N; i++) t2 = (t2*m) % MOD;
	t2 = (1 - t2 + MOD) % MOD;

	printf("%lld\n", (t1*mul_inv(t2, MOD)) % MOD);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1720 KB Output is correct
2 Correct 0 ms 1720 KB Output is correct
3 Correct 0 ms 1720 KB Output is correct
4 Correct 0 ms 1720 KB Output is correct
5 Correct 0 ms 1720 KB Output is correct
6 Correct 0 ms 1720 KB Output is correct
7 Correct 0 ms 1720 KB Output is correct
8 Correct 0 ms 1720 KB Output is correct
9 Correct 0 ms 1720 KB Output is correct
10 Correct 0 ms 1720 KB Output is correct
11 Correct 0 ms 1720 KB Output is correct
12 Correct 0 ms 1720 KB Output is correct
13 Correct 0 ms 1720 KB Output is correct
14 Correct 0 ms 1720 KB Output is correct
15 Correct 0 ms 1720 KB Output is correct
16 Correct 0 ms 1720 KB Output is correct
17 Correct 0 ms 1720 KB Output is correct
18 Correct 0 ms 1720 KB Output is correct
19 Correct 0 ms 1720 KB Output is correct
20 Correct 0 ms 1720 KB Output is correct
21 Correct 0 ms 1720 KB Output is correct
22 Correct 0 ms 1720 KB Output is correct
23 Correct 0 ms 1720 KB Output is correct
24 Correct 0 ms 1720 KB Output is correct
25 Correct 0 ms 1720 KB Output is correct
26 Correct 0 ms 1720 KB Output is correct
27 Correct 0 ms 1720 KB Output is correct
28 Correct 0 ms 1720 KB Output is correct
29 Correct 0 ms 1720 KB Output is correct
30 Correct 0 ms 1720 KB Output is correct