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})?p??q??(?p??q??≤?2??1??).

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}?Y??X??, 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(10?9??+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((p?q)+q)k+((p?q)?q)k2
时间: 2024-08-03 17:45:06

Coin的相关文章

NYOJ 698 A Coin Problem (斐波那契)

链接:click here 题意: 描述 One day,Jiameier is tidying up the room,and find some coins. Then she throws the coin to play.Suddenly,she thinks of a problem ,that if throw n times coin ,how many situations of no-continuous up of the coin. Hey,Let's solve the

Learn Python 016: Coin - a project of msc, unfinished.

import random class Coin: def __init__(self, rare=False, clean=True, **kwargs): for key,value in kwargs.items(): setattr(self,key,value) self.is_rare = rare self.is_clean = clean self.heads = heads if self.is_rare: self.value = self.original_value *

dp背包问题/01背包,完全背包,多重背包,/coin change算法求花硬币的种类数

一步一步循序渐进. Coin Change 具体思想:给你 N元,然后你有几种零钱S={S1,S2...,Sm} (每种零钱数量不限). 问:凑成N有多少种组合方式  即N=x1 * S1+x2*S2+...+xk*Sk (xk>=0,k=1,2..m) 设有f(x)中组合方式 有两种解答(自底向上回溯): 1.不用第m种货币   f(N,m-1) 2.用第m种货币 f(N-Sm,m) 总的组合方式为f(N,m)=f(N,m-1)+f(N-Sm,m) anything is nonsense,s

[LeetCode] Coin Change

You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins,

[LeetCode][JavaScript]Coin Change

Coin Change You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination o

Project Euler 78:Coin partitions

Coin partitions Let p(n) represent the number of different ways in which n coins can be separated into piles. For example, five coins can separated into piles in exactly seven different ways, so p(5)=7. OOOOOOOOO OOOO OOOOO O OOO OO OOO O O OO O O O

UVA 674 Coin Change

DP,背包的思想. 问 最多7489块钱.有多少种组成方式.面额分别为 1,5,10,25,50: 由于不限制硬币数量,所以完全背包,累加就可以了. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream

ACM-对称博弈之Coin Game——hdu3951

Coin Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1145    Accepted Submission(s): 668 Problem Description After hh has learned how to play Nim game, he begins to try another coin game w

[luogu2964][USACO09NOV][硬币的游戏A Coin Game]

题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game called Xoinc for them. Initially a stack of N (5 <= N <= 2,000) coins sits on the ground; coin i from the top has integer value C_i (1 <= C_i <=

1235 - Coin Change (IV)

   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given n coins, values of them are A1, A2 ... An respectively, you have to find whether you can pay K using the coins. You can use any coin at most two times. Input Input st