#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);
Q = P - Q;
if (Q == P) return !printf("1\n");
if (Q == 0) 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 = ((P - Q) * mul_inv(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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1720 KB |
Output is correct |
2 |
Correct |
0 ms |
1720 KB |
Output is correct |
3 |
Incorrect |
0 ms |
1720 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |