A Greeting from Qinhuangdao Gym - 102769A 2020ccpc秦皇岛分站赛

题意:

给你n个红球和m个蓝色球。然后以相等的概率随机选择了其中两个。选择两个红球的概率是多少?

题目:

Welcome to the CCPC Qinhuangdao Site!

Qinhuangdao is a beautiful coastal city full of charm, integrating historical heritage and modern civilization. It was named after the Emperor QinShiHuang’s east tour in 215 BC for seeking immortals.

The infiltration of more than 2000 years of history has left a rich cultural treasure here. Bo Yi, Shu Qi, Qi Jiguang, Cao Cao, and Mao Zedong, Many Heroes throughout the ages have endowed Qinhuangdao with the thousand-year cultural context, the unique and precious heritage, and the profound historical memory.
在这里插入图片描述

Pleasant natural scenery has shaped her beautiful appearance. Thousands of miles of Yan Mountains, the Great Wall, and the vast seas are miraculously met here. The blue sky, green land, blue sea, and golden sand gather together to welcome guests.

To toast your arrival, Alex prepared a simple problem to help you warm up.

Alex has red balls and blue balls. Then, Alex randomly chose two of these balls with equal probability. What is the probability that he chose two red balls?

Output the required probability in the form of irreducible fraction.

Input

The first line of input gives the number of test cases, . test cases follow.

For each test case, the only line contains two integers , where is the number of red balls and is the number of blue balls.

Output

For each test case, output one line containing “Case #x: y”, where is the test case number (starting from ), and is the answer in the form of irreducible fraction in format A/B.

If the required probability equals to zero, output 0/1. If the required probability equals to , output 1/1.

Example
Input

3
1 1
2 1
8 8

Output

Case #1: 0/1
Case #2: 1/3
Case #3: 7/30

分析:

1.注意审题,在红球数量小于2时,既不可能存在取两个红球的情况下直接输出0/1;
2.欧几里得算法。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int t,n,m,k,a,b;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    k=1;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&m);
        printf("Case #%d: ",k++);
        if(n<2)
            printf("0/1\n");
        else
        {
            a=n*(n-1);
            b=(n+m)*(n+m-1);
            printf("%d/%d\n",a/gcd(a,b),b/gcd(a,b));
        }
    }
    return  0;
}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值