Problem Description
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is ).
The question is, when Bob tosses the coin kk times, what's the probability that the frequency of the coin facing up is even number.
If the answer is , because the answer could be extremely large, you only need to print .
Input
First line an integer T, indicates the number of test cases (≤100).
Then Each line has 3 integer p,q,k(1≤p,q,k≤107) indicates the i-th test case.
Output
For each test case, print an integer in a single line indicates the answer.
Sample Input
2
2 1 1
3 1 2Sample Output
500000004
555555560
题意:t 组数据,每组给出 p、q、k 三个数,现已知抛出一个硬币正面朝上的概率为 q/p,问抛 k 次硬币后,正面朝上为偶数次的概率,要求对答案模 1E9+7
思路:
设 a=q/p 为每次抛硬币正面朝上的概率,则 b=1-a 为每次抛硬币反面朝上的概率
那么出现偶数次的概率为:
即 展开式与 中 x 的偶次方的系数,那么出现偶数次的概率为:
因此,出现奇数次的概率为:
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL quickModPow(LL a,LL b,LL mod){ LL res=1; a=a%mod; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1;} return res; }
LL getInv(LL a,LL mod){ return quickModPow(a,mod-2,mod); } // (a/b)%MOD=(a%MOD * getInv(b)%MOD)%MOD
const double EPS = 1E-10;
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
int main(){
int t;
scanf("%d",&t);
while(t--){
LL p,q,k;
scanf("%lld%lld%lld",&p,&q,&k);
LL invP=getInv(p,MOD); // p的逆元
LL inv2=getInv(2,MOD); // 2 的逆元
LL res=(q%MOD*invP%MOD)%MOD; // q/p;
res=2*res%MOD; // 2q/p
res=(1-res%MOD+MOD)%MOD; // 1-2q/p
res=quickModPow(res,k,MOD); //(1-2q/p)^k
res=(1+res%MOD)%MOD; // 1+(1-2q/p)^k
res=(res%MOD*inv2%MOD)%MOD; // (1+(1-2q/p)^k)/2
printf("%lld\n",res);
}
return 0;
}