Submission #19588

# Submission time Handle Problem Language Result Execution time Memory
19588 2016-02-24T22:01:12 Z gs12117 Ω (kriii4_P3) C++
100 / 100
0 ms 1084 KB
#include<stdio.h>
int mod=1000000007;
int p,q,n,m;
int a[110];
int b[110];
long long int f(long long int x,long long int y){
	if(y==0)return 1;
	long long int r=f(x,y/2);
	r*=r;
	r%=mod;
	if(y%2==0)return r;
	r*=x;
	r%=mod;
	return r;
}
int main(){
	int i;
	long long int res=0;
	scanf("%d%d%d%d",&p,&q,&n,&m);
	p=(p-q)*f(p,mod-2)%mod;
	b[1]=p;
	for(i=1;i<n;i++){
		b[i+1]=p*f(((long long int)b[i]*((p+mod-1)%mod)%mod+1)%mod,mod-2)%mod;
	}
	a[n]=1;
	for(i=n-1;i>0;i--){
		a[i]=(long long int)a[i+1]*b[i]%mod;
	}
	a[0]=0;
	printf("%d\n",a[m]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1084 KB Output is correct
2 Correct 0 ms 1084 KB Output is correct
3 Correct 0 ms 1084 KB Output is correct
4 Correct 0 ms 1084 KB Output is correct
5 Correct 0 ms 1084 KB Output is correct
6 Correct 0 ms 1084 KB Output is correct
7 Correct 0 ms 1084 KB Output is correct
8 Correct 0 ms 1084 KB Output is correct
9 Correct 0 ms 1084 KB Output is correct
10 Correct 0 ms 1084 KB Output is correct
11 Correct 0 ms 1084 KB Output is correct
12 Correct 0 ms 1084 KB Output is correct
13 Correct 0 ms 1084 KB Output is correct
14 Correct 0 ms 1084 KB Output is correct
15 Correct 0 ms 1084 KB Output is correct
16 Correct 0 ms 1084 KB Output is correct
17 Correct 0 ms 1084 KB Output is correct
18 Correct 0 ms 1084 KB Output is correct
19 Correct 0 ms 1084 KB Output is correct
20 Correct 0 ms 1084 KB Output is correct
21 Correct 0 ms 1084 KB Output is correct
22 Correct 0 ms 1084 KB Output is correct
23 Correct 0 ms 1084 KB Output is correct
24 Correct 0 ms 1084 KB Output is correct
25 Correct 0 ms 1084 KB Output is correct
26 Correct 0 ms 1084 KB Output is correct
27 Correct 0 ms 1084 KB Output is correct
28 Correct 0 ms 1084 KB Output is correct
29 Correct 0 ms 1084 KB Output is correct
30 Correct 0 ms 1084 KB Output is correct