# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19637 | javelinsman | Ω (kriii4_P3) | C++14 | 0 ms | 1724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |