Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is pq(pq≤21).
The question is, when Bob tosses the coin k times, what's the probability that the frequency of the coin facing up is even number.
If the answer is YX, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7).
Input Format
First line an integer T, indicates the number of test cases (T≤100).
Then Each line has 3 integer 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
題目來源
題意:拋k次硬幣,求正面朝上爲偶次數的概率,結果餘1e9+7k次扔取時,向上爲偶數的爲: C(k,0) *a^0 * b^k + C(k,2) *a^2 *b^(k-2)... + C(k,k)*a^k*b^0
所以結果應爲: ((a+b)^k +(a-b)^k )/2
又a+b=1,a=p/q,所以應爲(((p-2q)/p)^k+1)/2
關於除法逆元有(a / b) % p = (a * inv(a) ) % p = (a % p * inv(a) % p) % p
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 10000 + 10;
const double pi = acos(-1);
#define ll long long
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a));
const ll mod = 1e9 + 7;
ll q_mod(ll a, ll b)
{
ll res = 1;
while (b)
{
if (b & 1)
res = res*a%mod;
a = a*a%mod;
b >>= 1;
}
return res;
}
int main()
{
//freopen("Text.txt", "r", stdin);
int t;
ll p, q, k;
scanf("%d", &t);
while (t--)
{
scanf("%lld%lld%lld", &p, &q, &k);
ll ans = (p - 2 * q)*q_mod(p, mod - 2) % mod;//除法變乘法
ans = q_mod(ans, k);
ans = (ans + 1) % mod;
ans = ans*q_mod(2, mod - 2) % mod;
printf("%lld\n", ans);
}
return 0;
}