Submission #19637

# Submission time Handle Problem Language Result Execution time Memory
19637 2016-02-25T03:00:36 Z javelinsman Ω (kriii4_P3) C++14
100 / 100
0 ms 1724 KB
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;

ll C[111], X[111];

ll go(ll x,ll y){
    x%=MOD;
    if(y==0) return 1;
    if(y==1) return x;
    if(y%2) return go(x,y-1)*x%MOD;
    ll h = go(x,y/2);
    return h*h%MOD;
}

ll l_minus(ll x,ll y){
    return (x-y+MOD)%MOD;
}

ll l_mult(ll x,ll y){
    return x*y%MOD;
}

ll l_div(ll x,ll y){
    return l_mult(x,go(y,MOD-2));
}

ll ans[111];

int main(){
    int P,Q,n,K;
    cin>>P>>Q>>n>>K;
    ll p = l_div(Q,P), q = l_minus(1, p);

    C[1] = 0, X[1] = q;
    for(int i=2;i<n;i++){
        C[i] = l_mult(l_div(p,l_minus(1,l_mult(p,X[i-1]))),C[i-1]);
        X[i] = l_div(q,l_minus(1,l_mult(p,X[i-1])));
    }

    ans[n] = 1;
    for(int i=n-1;i>=1;i--){
        ans[i] = (C[i]+l_mult(X[i],ans[i+1]))%MOD;
    }

    cout<<ans[K];
}
# 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