Bob has a not even coin, every time he tosses the coin, the probability that the coin's front face up is \frac{q}{p}(\frac{q}{p} \le \frac{1}{2})​p​​q​​(​p​​q​​≤​2​​1​​).

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 \frac{X}{Y}​Y​​X​​, because the answer could be extremely large, you only need to print (X * Y^{-1}) \mod (10^9+7)(X∗Y​−1​​)mod(10​9​​+7).

Input Format

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

Then Each line has 33 integer p,q,k(1\le p,q,k \le 10^7)p,q,k(1≤p,q,k≤10​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

题目来源

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

【题解】

一道数学题,要结果的逆元,不过要先推公式,推出来再用二项式定理化简,就能写了。

【AC代码】

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int t;
ll p,q,k;ll quick(ll x,ll y)
{ll ans=1;while(y){if(y&1)ans=ans*x%mod;y>>=1;x=x*x%mod;}return ans;
}ll fact(ll x,ll y)
{ll ans=1;for(int i=x,j=1;j<=y;j++,i--)ans*=i;for(int i=1;i<=y;i++)ans/=i;return ans;
}void solve()
{ll ans=0;ll o=0,y;for(int i=0;i<=k;i+=2){o+=fact(k,i)*quick(p-q,k-i)*quick(q,i);}y=quick(p,k);pf("%lld   %lld\n",o,y);
}int main()
{sf("%d",&t);while(t--){sf("%lld%lld%lld",&p,&q,&k);
//        ll x=p>>1;
//        ll y=p/2-q;ll t1=quick(p,k);ll t2=quick(p-2*q,k);ll u=quick(2,mod-2);//注意不能直接除ll t3=((t1+t2)%mod)*u%mod;ll r=quick(p,k);ll ans=t3*quick(r,mod-2)%mod;pf("%lld\n",ans);}return 0;
}

2017 icpc 西安赛区 B.Coin(推公式+二项式定理)相关推荐

  1. 计蒜客 17115 2017 ICPC 西安网络赛 B Coin

    Problem nanti.jisuanke.com/t/17115 Reference 关于二项展开式系数和 [二项式定理][推导]计蒜客17115 2017 ACM-ICPC 亚洲区(西安赛区)网 ...

  2. 2017 ICPC西安区域赛 A - XOR (线段树并线性基)

    链接:https://nanti.jisuanke.com/t/A1607 题面: Consider an array AA with n elements . Each of its element ...

  3. 2017 ICPC西安区域赛 A - XOR ,线段树合并线性基

    题目链接:A - XOR 题意;给个数组,每次询问一个区间你可以挑任意个数的数字异或和 然后在或上k的最大值 题解:线性基不知道的先看这个,一个线性基可以log的求最大值把对应去区间的线性基求出来然后 ...

  4. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

  5. 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 u ...

  6. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B Coin (概率计算)

    传送门:  https://nanti.jisuanke.com/t/17115 Bob has a not even coin, every time he tosses the coin, the ...

  7. 计蒜客 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 u ...

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

    这个西安赛区大概是我们学校打得最好的一次了,因为数学题多,而且嘛,那个I竟然就是暴力,恭喜我们学校分了个机会 Coin 问答 只看题面 23.46% 1000ms 32768K Bob has a n ...

  9. 2017 ACM/ICPC 南宁赛区小结 By JSB @ Reconquista

    Statistics TYPE: Onsite Contest NAME: 2017 - ICPC - Asia Nanning PLAT: pc^2 TIME: 2017/11/26 09:00-1 ...

最新文章

  1. 腾讯竟然是这样招人的,哈哈哈哈哈
  2. android短信安全,[原创]分析了一款android短信木马
  3. STM32F4 HAL库开发 -- STM32F407引脚图
  4. CVE-2015-0235: GHOST – A Critical Vulnerability in the Glibc Library
  5. 计算机管理系统绪论,数据库系统概论 第一章 绪论
  6. mysql触发器delimiter_MySQL的触发器创建之注意事项(有关delimiter)
  7. 中美线径对照表_电缆里线规AWG的标准是什么?和其他公制如何对照使用?
  8. jdk环境变量的配置
  9. 无线覆盖技术的重要性
  10. 速达软件无法打开帐套数据库/一般性网络错误
  11. 建筑识图与构造【2】
  12. 关于Optical Zoom
  13. 为什么说串行比并行快
  14. 二分法求三次方根代码
  15. 无线点菜宝服务器,餐饮业电子产品无线点菜宝
  16. 虚拟屏幕与云计算————微软亚洲研究院
  17. Qt (高仿Visio)流程图组件开发(三) 图元基类如何定义,流程图多种图元类型实现
  18. 寻找子树和子孙树 ,家谱树
  19. 认识Linux操作系统
  20. 标普500指数下跌2.4%至盘中低点

热门文章

  1. html根据PC手机设置不同背景图,Html-根据不同的分辨率设置不同的背景图片
  2. 达芬奇系列教程1——安装及屏幕显示字体太小问题解决
  3. POM文件配置的详解
  4. 《计算机网络管理》_Chap2
  5. python文件的基本操作_Python文件基本操作
  6. 电路及电路设计经验技巧大合集
  7. c语言300行代码大作业,C语言300行代码
  8. 基于Sphinx的中文全文检索引擎Coreseek的安装
  9. 目前主流服务器厂商有哪些?都有什么型号
  10. 计算机网络的常见面试题