题库链接:https://nanti.jisuanke.com/t/17115
Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is .
The question is, when Bob tosses the coin
times, what's the probability that the frequency of the coin facing up is even number.
If the answer is , because the answer could be extremely large, you only need to print
Input Format
First line an integer , indicates the number of test cases ().
Then Each line has integer 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
题目来源
【解析】:
概率计算,但最终结果不用除法,而用逆元。
只算分子即可,分母就是p的k次幂
分子的计算
【代码】:
#include <stdio.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll qpow(ll n,ll m){n%=mod;ll ans=1;while(m){if(m%2)
ans=(ans*n)%mod;m/=2;n=(n*n)%mod;}return ans;}
ll inv(ll b){
return b==1?1:(mod-mod/b)*inv(mod%b)%mod;
}
int main()
{
ll t,p,q,k;
cin>>t;
while(t--)
{
scanf("%lld%lld%lld",&p,&q,&k);
ll zi=qpow(p,k)+qpow(p-2*q,k);//分子
zi=zi%mod*inv(2)%mod;
ll mu=qpow(p,k)%mod;//分母
ll ans=zi*inv(mu)%mod;
printf("%lld\n",ans);
}
return 0;
}