题库链接: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 ICPC2017网络赛(西安)B coin (概率计算)_ci.

The question is, when Bob tosses the coin 

ICPC2017网络赛(西安)B coin (概率计算)_ci_02times, what's the probability that the frequency of the coin facing up is even number.

If the answer is ICPC2017网络赛(西安)B coin (概率计算)_概率_03, because the answer could be extremely large, you only need to print 

Input Format

First line an integer ICPC2017网络赛(西安)B coin (概率计算)_#include_04, indicates the number of test cases (ICPC2017网络赛(西安)B coin (概率计算)_ci_05).

Then Each line has ICPC2017网络赛(西安)B coin (概率计算)_#include_06 integer ICPC2017网络赛(西安)B coin (概率计算)_ci_07 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 亚洲区(西安赛区)网络赛


【解析】:

概率计算,但最终结果不用除法,而用逆元。

只算分子即可,分母就是p的k次幂

分子的计算

ICPC2017网络赛(西安)B coin (概率计算)_ios_08

【代码】:

#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;
}