• F


    Description

    There is a hill with n holes around. The holes are signed from 0 to n-1. 



    A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes. 

    Input

    The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648). 

    Output

    For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line. 

    Sample Input

    2
    1 2
    2 2

    Sample Output

    NO
    YES

    题意:有一座环形山脉,山脉中一共有n个洞,编号为0~n-1,现在有一头狼,从编号为0的洞开始找兔子,每隔m个洞他就会进洞一次,直到回到起点,让你求兔子待在哪些洞中是安全的,如果这种洞存在就输出YES,否则输出NO
    分析:我的想法是只要考虑有没有安全洞的情况,就将题目分成了两种情况,当n不为0时,只要m等于1那就没有安全洞存在(因为狼会将每个洞都遍历一遍),其他时候安全洞都是存在的;当n为1时,没有安全洞。但是好像不对,没弄懂。
    参照别人的想法,本题的实质是判断两个数是否互质。这个也好理解

    AC代码:
    #include<iostream>
    using namespace std;
    int main()
    {
        int t,m,n,k;
        cin>>t;
        while(t--)
        {
            cin>>m>>n;
            while(n!=0)
            {
                k=m%n;
                m=n;
                n=k;
            }
            if(m!=1) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        return 0;
    
    }







  • 相关阅读:
    170829-关于AOP面向切面编程
    170826-关于spring的知识点及练习
    170814-17关于javaweb的知识点
    scrapy之手机app抓包爬虫
    tornado之WebSocket
    Tornado异步(2)
    tornado异步(1)
    爬虫之动态HTML处理(Selenium与PhantomJS )动态页面模拟点击
    爬虫之动态HTML处理(Selenium与PhantomJS )执行 JavaScript 语句
    爬虫之动态HTML处理(Selenium与PhantomJS )网站模拟登录
  • 原文地址:https://www.cnblogs.com/lbyj/p/5730819.html
Copyright © 2020-2023  润新知