Coin
Posted 十年换你一句好久不见
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)\\frac{q}{p}(\\frac{q}{p} \\le \\frac{1}{2})pq(pq≤21).
The question is, when Bob tosses the coin kkk times, what\'s the probability that the frequency of the coin facing up is even number.
If the answer is XY\\frac{X}{Y}YX, because the answer could be extremely large, you only need to print (X∗Y−1)mod(109+7)(X * Y^{-1}) \\mod (10^9+7)(X∗Y−1)mod(109+7).
Input Format
First line an integer TTT, indicates the number of test cases (T≤100T \\le 100T≤100).
Then Each line has 3 integer p,q,k(1≤p,q,k≤107).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
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <map> #include <set> using namespace std; #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) #define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.141592653589793238462 #define ios() ios::sync_with_stdio(true) #define INF 1044266558 #define mem(a) (memset(a,0,sizeof(a))) typedef long long ll; ll p,q,k,n; ll quick_mod(ll x,ll y) { ll ans=1; while(y) { if(y&1) ans=ans*x%MOD; y>>=1; x=x*x%MOD; } return ans; } int main() { scanf("%lld",&n); while(n--) { scanf("%lld%lld%lld",&p,&q,&k); ll ans=quick_mod(p-2*q,k); ll pos=quick_mod(p,k); pos=quick_mod(pos,MOD-2); printf("%lld\\n",((1+ans*pos%MOD)%MOD)*quick_mod(2,MOD-2)%MOD); } return 0; }
1pk
以上是关于Coin的主要内容,如果未能解决你的问题,请参考以下文章
Lightoj 1235 - Coin Change (IV) 二分
Educational Codeforces Round 112 (Rated for Div. 2)-C. Coin Rows-题解
Educational Codeforces Round 112 (Rated for Div. 2)-C. Coin Rows-题解