2017 ACM-ICPC 亚洲区(西安赛区)网络赛: B. 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 )
The question is, when Bob tosses the coin kk times, what’s the probability that the frequency of the coin facing up is even number.

If the answer is XY ​​ , because the answer could be extremely large, you only need to print (XY1)mod(109+7).

Input Format

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

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

思路:一个高中的组合数学题。。。。。

ans=i=0i2k(qp)2i(1qp)(k2i)C2ik

ans=1pki=0i2kq2i(pq)(k2i)C2ik

ans=1pk((pq)+q)k+((pq)q)k2

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
long long POW(long long x,long long n)
{
    long long res=1;
    while(n)
    {
        if(n&1)res=(res*x)%MOD;
        x=(x*x)%MOD;
        n/=2;
    }
    return res;
}
int main()
{
    int T;cin>>T;
    while(T--)
    {
        long long p,q,k;
        scanf("%lld%lld%lld",&p,&q,&k);
        long long x=POW(p-2*q,k);
        long long y=POW(p,k);
        cout<<(  ((1+x*POW(y,MOD-2))%MOD) * POW(2,MOD-2) )%MOD<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值