# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19312 | ainta | Ω (kriii4_P3) | C++98 | 0 ms | 1084 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<stdio.h>
long long Mod = 1000000007, P, Q, N, K, C[110][2], Res[110];
long long Inv(long long a){
long long b = Mod - 2, r = 1;
while(b){
if(b%2)r=r*a%Mod;
a=a*a%Mod;b/=2;
}
return r;
}
int main(){
int i;
scanf("%lld%lld%lld%lld",&P,&Q,&N,&K);
C[1][0] = 0, C[1][1] = (P-Q)*Inv(P)%Mod;
for(i=1;i+1<N;i++){
C[i+1][0] = Q*C[i][0]%Mod*Inv((P-C[i][1]*Q%Mod+Mod)%Mod)%Mod;
C[i+1][1] = (P-Q)%Mod*Inv((P-C[i][1]*Q%Mod+Mod)%Mod)%Mod;
}
Res[N] = 1;
for(i=N-1;i>=1;i--){
Res[i] = (Res[i+1]*C[i][1]+C[i][0])%Mod;
}
printf("%lld\n",Res[K]);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |