设为首页 加入收藏

TOP

HDU2504 又见GCD
2015-07-20 18:04:16 来源: 作者: 【 】 浏览:4
Tags: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
Input 第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。

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

Sample Input
2
6 2
12 4

Sample Output
4
8

Source

#include 
   
    

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\n", c);
    }
    return 0;
}

   


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu1251统计难题(字典树) 下一篇hdu4864Task(贪心)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: