• SDNU 1254.Problem B. SOS(水题)


    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
    ", miao-t, c);
        }
        return 0;
    }
  • 相关阅读:
    99. 恢复二叉搜索树
    337. 打家劫舍 III(dp+dfs)
    45. 跳跃游戏 II
    贪心
    460. LFU 缓存
    213. 打家劫舍 II(dp)
    MyScript 开发文档
    Android 全面屏体验
    Android Studio 导入自己编译的 framework jar
    cmake常用配置项
  • 原文地址:https://www.cnblogs.com/RootVount/p/10993078.html
Copyright © 2020-2023  润新知