首页 > 其他 > 详细

Coin

时间:2017-09-17 12:48:07      阅读:200      评论:0      收藏:0      [点我收藏+]

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})?p??q??(?p??q???2??1??).

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 XY\frac{X}{Y}?Y??X??, 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)(X?Y??1??)mod(10?9??+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\n",((1+ans*pos%MOD)%MOD)*quick_mod(2,MOD-2)%MOD);
    }
    return 0;
}

 



1pk((p?q)+q)k+((p?q)?q)k2

Coin

原文:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7535017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!