SDNU 1254.Problem B. SOS(水题)

本文介绍了一种算法,用于解决给定两个整数A和B,在已知最大公约数等于B但丢失了第三个整数C的情况下,找到满足条件的最小的C。通过不断累加B并检查与A的最大公约数是否等于B,最终确定了C的值。

Description

Lulichuan is a good captain, He is thinking every day how to make his team stronger,However, his team members always disappointed him.They always make mistakes, like WA, TLE, MLE, CE,PE.....Today, he thought of a good way to make team members stronger. That is to make the peoblem simpler. So he got a easy problem, now, we have three numbers, a, b, c,

We know gcd(a,c) = b,  but, we lose the c, we only know a, b, b != c,we want to know the smallest c.

(0 < a, b, c< 10000000)

Input

 T(0 < T <= 10000) T is TestCase

 a, b(0 < a, b<=10000000)

Output

 Case #TestCase: answer

Sample Input

2
6 2
12 4

Sample Output

Case #1: 4
Case #2: 8

Source

Unknown
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int t, a, b, c;

int gcd(int a, int b)
{
    if(a%b == 0)return b;
    return gcd(b, a%b);
}

int main()
{
    scanf("%d", &t);
    int miao = t;
    while(t--)
    {
        scanf("%d%d", &a, &b);
        c = b*2;
        while(gcd(a, c) != b)c += b;
        printf("Case #%d: %d\n", miao-t, c);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/RootVount/p/10993078.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值