Problem Description
The Children’s Day has passed for some days .Has you remembered
something happened at your childhood? I remembered I often played a game
called hide handkerchief with my friends.
Now I introduce the game
to you. Suppose there are N people played the game ,who sit on the
ground forming a circle ,everyone owns a box behind them .Also there is a
beautiful handkerchief hid in a box which is one of the boxes .
Then
Haha(a friend of mine) is called to find the handkerchief. But he has a
strange habit. Each time he will search the next box which is separated
by M-1 boxes from the current box. For example, there are three boxes
named A,B,C, and now Haha is at place of A. now he decide the M if equal
to 2, so he will search A first, then he will search the C box, for C
is separated by 2-1 = 1 box B from the current box A . Then he will
search the box B ,then he will search the box A.
So after three times
he establishes that he can find the beautiful handkerchief. Now I will
give you N and M, can you tell me that Haha is able to find the
handkerchief or not. If he can, you should tell me "YES", else tell me
"POOR Haha".
 

Input
There will be several test cases; each case input contains two
integers N and M, which satisfy the relationship: 1<=M<=100000000
and 3<=N<=100000000. When N=-1 and M=-1 means the end of input
case, and you should not process the data.
 

Output
For each input case, you should only the result that Haha can find the handkerchief or not.
 

Sample Input
3 2
-1 -1
 

Sample Output
YES
 

当从m开始找时,如果m与n有公约数时,在找盒子时,就只会在这些约数的倍数之间找,而不是约数倍数的盒子就永远也不会被找到,所以当m与n的最大公约数为1,即m与n互质时才能找遍所有的盒子。

(一)

#include<stdio.h>
#include<math.h>
int Zhisu(int a,int b)
{
    if((a-b)==0)
        return b;
    else
        Zhisu(b,abs(a-b));
}
void main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    while(a!=-1 && b!=-1)
    {
        if(Zhisu(a,b)==1)
            printf("YES\n");
        else
            printf("POOR Haha\n");
        scanf("%d %d",&a,&b);
    }
}

(二)

#include<stdio.h>
void main()
{
    int a,b,c;
    while(1)
    {
        scanf("%d %d",&a,&b);
        if(a==-1 && b==-1)
            return;
        while(b!=0)
        {
            c=a%b;
            a=b;
            b=c;
        }
        if(a==1)
            printf("YES\n");
        else
            printf("POOR Haha\n");
    }
}

hide handkerchief的更多相关文章

  1. 【HDOJ】2104 hide handkerchief

    Problem Description The Children’s Day has passed for some days .Has you remembered something happen ...

  2. HDU 2104 hide handkerchief

    题解:由题目可以知道,如果n和m的最大公约数不为1,那么总有箱子是无法遍历的,所以求一遍GCD就可以判断了. 注意点:一定要记住判断是==,在做题时又忘了. #include <cstdio&g ...

  3. hide handkerchief(hdu2104)

    思考:这种找手绢就是,在判断是否互质.用辗转相除法(用来求最大公约数:a)进行判断.r=a%b;a=b;b=r;循环限制条件:除数b=0是结束除法.如果这时被除数a=1,则表示两个互质. #inclu ...

  4. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  5. HOJ———丢手绢

    hide handkerchief Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 2104(判断互素)

    hide handkerchief Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. #C++初学记录(遍历)

    hide handkerchief Problem Description The Children's Day has passed for some days .Has you remembere ...

  8. 数学--数论--HDU 2104 丢手绢(离散数学 mod N+ 剩余类 生成元)+(最大公约数)

    The Children's Day has passed for some days .Has you remembered something happened at your childhood ...

  9. View and Data API Tips: Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

随机推荐

  1. 初次搭建spring-boot 整合ssm(有许多小坑)

    首先,我是采用官网下载,版本最好选择1.5.16的(这是重点) 下载完毕后,用idea打开解压后的项目. 1.整合spring-mvc 在pom.xml中加入web依赖 <dependency& ...

  2. C# mysql 插入数据,中文乱码

    用C#操作mysql时, 插入数据中文都是乱码,只显示问号,数据库本身使用的是utf-8字符. 网上百度一下有两种解决办法: 一种是在执行语句前面设置,如:MySQLCommand mCommand ...

  3. 解决loadrunner录制页面的乱码问题

    以下亲自验证了的:好用.     三步解决loadrunner录制页面的乱码问题 第一步:去lr 的vugen的Tools -> Recoding Options -> Advanced ...

  4. Maximum Product Subarray LT152

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...

  5. Spring 常见注解

    @Component:标准一个普通的spring Bean类. @Controller:标注一个控制器组件类. @Service:标注一个业务逻辑组件类. @Repository:标注一个DAO组件类 ...

  6. fastcgi 环境变量例子

    例如请求的url http://172.28.250.184:8099/aa.php?var=ccccc&value=bbbbbb 前两个字节分别代表  变量名长度  和 变量值长度. 0x0 ...

  7. Grunt教程——安装Grunt

    Grunt教程--安装Grunt 作者:大漠 日期:2013-11-04 点击:3124 tools grunt 在上一节<Grunt教程--初涉Grunt>一文中介绍了Grunt是什么, ...

  8. DockerDesktop简单安装和使用

    一.在windows10下,安装DockerDesktop: 1.检查windows版本为企业版或专业版,并开启Hyper-v系统设置:电脑的控制面板->程序->启用或关闭Windows功 ...

  9. 自定义注解与validation结合使用案例

    编写validation自定义注解: @Target({ ElementType.FIELD, ElementType.METHOD })@Retention(RetentionPolicy.RUNT ...

  10. [ASP.NET]使用Layer简介

    layer是一款近年来备受青睐的web弹层组件,她具备全方位的解决方案,致力于服务各水平段的开发人员,您的页面会轻松地拥有丰富友好的操作体验. 在与同类组件的比较中,layer总是能轻易获胜.她尽可能 ...