B. Coin(组合数+快速幂,费马小求逆元)
1000ms 32768K
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)
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 XY , because the answer could be extremely large, you only need to print(X∗Y−1)mod(109+7).
Input Format
First line an integer T, indicates the number of test cases (T≤100).
Then Each line has 3 integer p,q,k(1≤p,q,k≤107) indicates the i-th test case.
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 亚洲区(西安赛区)网络赛
题意:(可能我英文菜,但是确定我每个地方都知道。。。)
给你一个不均匀的硬币,掷一次出现正面的概率是q/p,掷硬币k次出现正面偶数次的概率和为X/Y,输出((X*Y^(-1))%(1e9+7).
分析:
这里Y^(-1)就用逆元求就是了
这里我理解错了,偶数次,把0给漏了。。
求概率和转化为次数为求出现正面偶数次的情况,然后就是组合数公式的推理
看过程点击http://blog.youkuaiyun.com/winter2121/article/details/78005036?locationNum=10&fps=1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <string>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
typedef long long LL;
const double eps=1e-6;
const int N=1e3+5;
const int mod=1e9+7;
LL pow_mod(LL a,LL b)
{
LL ans=1;
a%=mod;
while(b>0)
{
if(b&1) ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
LL fermat(LL a,LL p)///费马小定理求逆元
{
return pow_mod(a,p-2);
}
int main()
{
int T;
cin>>T;
while(T--)
{
LL p,q,k;
cin>>p>>q>>k;
// printf("%d %d\n",p,k);
LL tmp=(pow_mod(p,k)+pow_mod(p-2*q,k))%mod*fermat(2,mod)%mod;
LL tt=(LL)pow_mod(p,k);
//printf("tt=%lld tmp=%lld\n",tt,tmp);
cout<<(tmp*fermat(tt,mod))%mod<<endl;
}
return 0;
}
C. Sum
1000ms 32768K
Define the function S(x)S(x) for xx is a positive integer. S(x)S(x) equals to the sum of all digit of the decimal expression of xx. Please find a positive integer kk that S(k*x)\%233=0S(k∗x)%233=0.
Input Format
First line an integer TT, indicates the number of test cases (T \le 100T≤100). Then Each line has a single integer x(1 \le x \le 1000000)x(1≤x≤1000000) indicates i-th test case.
Output Format
For each test case, print an integer in a single line indicates the answer. The length of the answer should not exceed 20002000. If there are more than one answer, output anyone is ok.
样例输入
1
1
样例输出
89999999999999999999999999
题目来源
2017 ACM-ICPC 亚洲区(西安赛区)网络赛
分析:任意数乘9得到的数的数位和仍然是9的倍数,直接输出233个9就可以了