# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
19446 |
2016-02-24T12:40:26 Z |
xhae |
Ω (kriii4_P3) |
C++14 |
|
0 ms |
1724 KB |
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const long long MOD = 1000000007;
long long P, Q, N, K;
long long p[101], q[101], d[101];
long long inv(long long tar) {
long long ret = 1;
for(int i = 30; i >= 0; i--) {
ret = ret * ret % MOD;
if((1ll << i) & (MOD - 2)) ret = ret * tar % MOD;
}
return ret;
}
int main(void) {
cin >> P >> Q >> N >> K;
if(K == 0) printf("0\n");
else if(K == N) printf("1\n");
else {
long long gcdv = __gcd(Q, P);
long long a = Q / gcdv * inv(P / gcdv) % MOD;
gcdv = __gcd(P - Q, P);
long long b = (P - Q) / gcdv * inv(P / gcdv) % MOD;
p[N - 1] = a, q[N - 1] = b;
for(int i = N - 2; i > 0; i--) {
long long base = ((1 - b * p[i + 1] % MOD) + MOD) % MOD;
p[i] = a * inv(base) % MOD;
q[i] = b * q[i + 1] % MOD * inv(base) % MOD;
}
d[0] = 0;
for(int i = 1; i < N; i++) d[i] = (d[i - 1] * p[i] % MOD + q[i]) % MOD;
cout << d[K];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1724 KB |
Output is correct |
2 |
Correct |
0 ms |
1724 KB |
Output is correct |
3 |
Correct |
0 ms |
1724 KB |
Output is correct |
4 |
Correct |
0 ms |
1724 KB |
Output is correct |
5 |
Correct |
0 ms |
1724 KB |
Output is correct |
6 |
Correct |
0 ms |
1724 KB |
Output is correct |
7 |
Correct |
0 ms |
1724 KB |
Output is correct |
8 |
Correct |
0 ms |
1724 KB |
Output is correct |
9 |
Correct |
0 ms |
1724 KB |
Output is correct |
10 |
Correct |
0 ms |
1724 KB |
Output is correct |
11 |
Correct |
0 ms |
1724 KB |
Output is correct |
12 |
Correct |
0 ms |
1724 KB |
Output is correct |
13 |
Correct |
0 ms |
1724 KB |
Output is correct |
14 |
Correct |
0 ms |
1724 KB |
Output is correct |
15 |
Correct |
0 ms |
1724 KB |
Output is correct |
16 |
Correct |
0 ms |
1724 KB |
Output is correct |
17 |
Correct |
0 ms |
1724 KB |
Output is correct |
18 |
Correct |
0 ms |
1724 KB |
Output is correct |
19 |
Correct |
0 ms |
1724 KB |
Output is correct |
20 |
Correct |
0 ms |
1724 KB |
Output is correct |
21 |
Correct |
0 ms |
1724 KB |
Output is correct |
22 |
Correct |
0 ms |
1724 KB |
Output is correct |
23 |
Correct |
0 ms |
1724 KB |
Output is correct |
24 |
Correct |
0 ms |
1724 KB |
Output is correct |
25 |
Correct |
0 ms |
1724 KB |
Output is correct |
26 |
Correct |
0 ms |
1724 KB |
Output is correct |
27 |
Correct |
0 ms |
1724 KB |
Output is correct |
28 |
Correct |
0 ms |
1724 KB |
Output is correct |
29 |
Correct |
0 ms |
1724 KB |
Output is correct |
30 |
Correct |
0 ms |
1724 KB |
Output is correct |