hdu 2504 又见gcd

http://acm.hdu.edu.cn/showproblem.php?pid=2504
hint: 暴力

#include <iostream>

using namespace std;
int gcd(int m, int n)
{
    if(n==0)
    return m;
    return gcd(n, m%n);
}
int main()
{
    int a,b,t;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        for(int i=2*b; i<=a; i++)
        {
            if(gcd(i,a)==b)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}
时间: 2024-09-19 09:44:56

hdu 2504 又见gcd的相关文章

HDU 4497 GCD and LCM (数论&amp;amp;组合数学)

GCD and LCM http://acm.hdu.edu.cn/showproblem.php?pid=4497 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Problem Description Given two positive integers G and L, could you tell me how many solutions of (x, y, z) the

hdu 1695 GCD【欧拉函数+容斥原理】

GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6253    Accepted Submission(s): 2291 Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y

HDU 2985 Another lottery(水题)

HDU 2985:http://acm.hdu.edu.cn/showproblem.php?pid=2985 大意: 给你n个人,每个人买m次彩票,第i次的奖金是2的i次方,求每个人赢的比其他人都多的可能性是多少. 思路: 就是只看最后一次就行,2的i次方,对于每个人来说,最后一次的奖要比前面的大很多,所以直接只看最后一次,算出概率gcd一下就行了. 更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ #i

HDU 2047 阿牛的EOF牛肉串 (递推)

阿牛的EOF牛肉串 http://acm.hdu.edu.cn/showproblem.php?pid=2047 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的友谊,阿牛准备做点什么来纪

HDU 4254 A Famous Game (概率&amp;amp;组合数学公式)

A Famous Game http://acm.hdu.edu.cn/showproblem.php?pid=4254 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Mr. B and Mr. M like to play with balls. They have many balls colored in blue and red. F

F——RGCDQ (HDU 5317)

点击打开链接 Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What's RGCDQ? Please let me explain it

hdu 1452 Happy2004

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1452 解题思路:我也是根据一些网上的大牛的代码,自己慢慢整,其实也不是很明白, 计算 2004^X的因子和 s(2004^X) mod M, M=29 s(2004^X)%29 因子和 s是积性函数,即 :gcd(a,b)=1==> s(a*b)= s(a)*s(b) 2004^X=4^X * 3^X *167^X s(2004^X)= s(2^(2X))* s(3^X) * s(167^X) 如果

Grand Central Dispatch (GCD)

Grand Central Dispatch (GCD) Reference Grand Central Dispatch (GCD) comprises language features, runtime libraries, and system enhancements that provide systemic, comprehensive improvements to the support for concurrent code execution on multicore ha

hdu 5349 MZL&amp;#39;s simple problem

hdu 5349 的传送门 Problem Description A simple problem Problem Description You have a multiple set,and now there are three kinds of operations: 1 x : add number x to set 2 : delete the minimum number (if the set is empty now,then ignore it) 3 : query the