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).
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.
For each test case, print an integer in a single line indicates the answer.
2 2 1 1 3 1 2
500000004 555555560
#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;
}