zoukankan      html  css  js  c++  java
  • HDU2504 又见GCD

    又见GCD

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 9984    Accepted Submission(s): 4157


    Problem Description
    有三个正整数a,b,c(0<a,b,c<10^6),当中c不等于b。若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c。
     

    Input
    第一行输入一个n,表示有n组測试数据,接下来的n行,每行输入两个正整数a,b。
     

    Output
    输出相应的c,每组測试数据占一行。
     

    Sample Input
    2 6 2 12 4
     

    Sample Output
    4 8
     

    Source

    #include <stdio.h>
    
    int gcd(int a, int b){
        return b ? gcd(b, a % b) : a;
    }
    
    int main()
    {
        int n, a, b, c;
        scanf("%d", &n);
        while(n--){
            scanf("%d%d", &a, &b);
            for(c = b << 1; ; c += b){
                if(gcd(a, c) == b) break;
            }
            printf("%d
    ", c);
        }
        return 0;
    }
    


  • 相关阅读:
    Codeforces Round #239(Div. 2) 做后扯淡玩
    hdu 3507 Print Article
    prufer序列
    POJ 2778 DNA Sequence
    Codeforces Round #237 (Div. 2)
    poj3352
    图论知识
    POJ 2186
    Codeforces Round #236 (Div. 2)
    POJ 2823 Sliding Window
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5184796.html
Copyright © 2011-2022 走看看