2017 ACM-ICPC西安网赛B-Coin
B-Coin
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is \frac{q}{p}(\frac{q}{p} \le \frac{1}{2})pq(pq≤21).
The question is, when Bob tosses the coin kktimes, what's the probability that the frequency of the coin facing up is even number.
If the answer is \frac{X}{Y}YX, because the answer could be extremely large, you only need to print (X * Y^{-1}) \mod (10^9+7)(X∗Y−1)mod(109+7).
Input Format
First line an integer TT, indicates the number of test cases (T \le 100T≤100).
Then Each line has 33 integer p,q,k(1\le p,q,k \le 10^7)p,q,k(1≤p,q,k≤107) indicates the i-th test case.
Output Format
For each test case, print an integer in a single line indicates the answer.
样例输入
2 2 1 1 3 1 2
样例输出
500000004 555555560
题目来源
1 //2017-10-24 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define ll long long 7 8 using namespace std; 9 10 const int MOD = 1000000007; 11 12 ll quickPow(ll a, ll n){ 13 ll ans = 1; 14 while(n){ 15 if(n&1) 16 ans = (a*ans)%MOD; 17 a = (a*a)%MOD; 18 n >>= 1; 19 } 20 return ans; 21 } 22 23 int main() 24 { 25 ll p, q, k, T; 26 cin>>T; 27 while(T--){ 28 cin>>p>>q>>k; 29 ll X = quickPow(p-2*q, k); 30 ll Y = quickPow(p, k); 31 cout<<(((1+X*quickPow(Y, MOD-2))%MOD) * quickPow(2, MOD-2))%MOD<<endl; 32 } 33 34 return 0; 35 }