HDU 17新生赛 正品的概率【数论-概率论】

正品的概率

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 848    Accepted Submission(s): 67


Problem Description
袋中有m枚正品硬币,n枚次品硬币(次品硬币两面都有国徽),在袋中任取一枚,将它投掷k次,已知每次得到的都是国徽,那么这枚硬币是正品的概率是多少?
 
Input
输入包含多组数据,每组占一行包含3个正整m,n,k (1<=m,n,k<=50)。
 
Output
每组输出一行,包含一个最简分数,硬币为正品的概率。
 
Sample Input
1 1 1
 
Sample Output
1/3
 
【分析】:手写gcd,参数少了个long!我气死!还是用库函数吧!
【代码】:
#include <bits/stdc++.h>

using namespace std;

#define LL long long

LL pows(long long x,long long n)
{
    LL res=1;
    while(n)
    {
        if(n&1)
            res*=x;
        n>>=1;
        x*=x;
    }
    return res;
}

int main()
{
    LL n,m;
    double k;
    while(~scanf("%I64d%I64d%I64d",&m,&n,&k))
    {

        LL x=__gcd(m,(m + n*pows(2,k)));
        printf("%I64d/%I64d
",m/x,(m + n*pows(2,k))/x);
    }
}
贝叶斯
原文地址:https://www.cnblogs.com/Roni-i/p/7897185.html