2017 ACM-ICPC 亚洲区(西安赛区)网络赛 - 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)pq(pq21).

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 XYYX, because the answer could be extremely large, you only need to print (X∗Y−1)109+7)(XY1)mod(109+7).

Input Format

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

Then Each line has 33 integer p,q,k(1≤p,q,k≤107)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
题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛


题意:

投硬币,正面朝上是q/p的概率,求投k次,偶数次正面朝上的概率;

(a+b)^k=C(0,k)*a^0*b^k+C(1,k)*a^1*b^(k-1)+……+C(k,k)*a^k&b^0.

那么(a-b)^k+(a+b)^k=上面式子的偶数项合,即答案。

#include <iostream>
#include <stdio.h>
#include <stack>
#include <vector>
#include <math.h>
using namespace std;
#define  LL long long
const LL mod = 1e9+7;
LL qkm(LL base,LL mi)
{
    LL ans=1;
    base%=mod;
    while(mi)
    {
        if(mi&1) ans=ans*base%mod;
        base=base*base%mod;
        mi>>=1;
    }
    return ans;
}
int main()
{
    LL T;
    scanf("%lld",&T);
    while(T--)
    {
        LL q,p,k;scanf("%lld %lld %lld",&p,&q,&k);
        LL ans=(1+qkm((mod+1-2*q*qkm(p,mod-2)%mod),k)%mod)*qkm(2,mod-2)%mod;
        printf("%lld\n",ans);
    }
}



qp(qp≤12)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值