Coin

Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is qp(qp≤12)frac{q}{p}(frac{q}{p} le frac{1}{2})pq​​(pq​​21​​).

The question is, when Bob tosses the coin kkk times, what's the probability that the frequency of the coin facing up is even number.

If the answer is XYfrac{X}{Y}YX​​, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7)(X * Y^{-1}) mod (10^9+7)(XY1​​)mod(109​​+7).

Input Format

First line an integer TTT, indicates the number of test cases (T≤100T le 100T100).

Then Each line has 3 integer p,q,k(1≤p,q,k≤107).7​​) 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

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll p,q,k,n;
ll quick_mod(ll x,ll y)
{
    ll ans=1;
    while(y)
    {
        if(y&1) ans=ans*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return ans;
}
int main()
{
    scanf("%lld",&n);
    while(n--)
    {
        scanf("%lld%lld%lld",&p,&q,&k);
        ll ans=quick_mod(p-2*q,k);
        ll pos=quick_mod(p,k);
        pos=quick_mod(pos,MOD-2);
        printf("%lld
",((1+ans*pos%MOD)%MOD)*quick_mod(2,MOD-2)%MOD);
    }
    return 0;
}


1pk((pq)+q)k+((pq)q)k2
原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7535017.html