Submission #19312

#TimeUsernameProblemLanguageResultExecution timeMemory
19312aintaΩ (kriii4_P3)C++98
100 / 100
0 ms1084 KiB
#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 timeMemoryGrader output
Fetching results...