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. Linux服务器有什么优势?

    为您的企业选择服务器时,您可以选择几种不同的选项.虽然许多公司使用基于Windows的服务器,但选择Linux服务器可能是您最好的选择.为什么Linux服务器比其他服务器更好?以下是使用Linux服务 ...

  2. 洛谷1984 [SDOI2008]烧水问题

    一道找规律 原题链接 显然要将烧得的温度最大化利用,即每次都去热传递. 设水沸腾为\(x\). 第一杯直接烧水,需提高\(x\). 第二杯先与第一杯进行热传递,这样只需提高\(\dfrac{x}{2} ...

  3. 无法将参数 1 从“WCHAR [256]”转换为“const char *”

    https://blog.csdn.net/zhangxuechao_/article/details/81064037 字符集 修改为未设置 然后再修改回来unicode  居然好了

  4. eclipse项目两个红点

    Description Resource Path Location Type Unbound classpath container: 'JRE Sy 选中项目右键build path 选择libr ...

  5. msgs no .h file

    1.单独编译包,catkin_make --pkg 包名,failed,则 2.进入build下对应的msgs包中,使用make,以及make install,failed,则 3.使用catkin_ ...

  6. openssl RSA加密方法初识

    作为非对称加密算法,有两对密钥 一般用法 加密结果=RSA_EN(数据,公钥); 解密结果=RSA_DE(数据,私钥); RSA填充 (RSA_public_encrypt和RSA_private_d ...

  7. IOS初级:UITableView

    先来看一下tableview 的结构(plain style). --------------------------------------       + header               ...

  8. c#里如何实现讲一个字符串数组例如 “112,221”转化成两个字符串数组“112” “221” 中间以逗号隔开

    比如是S [0]="123,223" S[1]="111,222" ....... 想转化为 SX[0]="123" SX[1]=" ...

  9. JNI,RegisterNative参数解析

    Register native method - 数据类型和method descriptor 使用JNI时,为了使得虚拟机可以找到在C/C++ code中定义的native方法,有两种机制可以用,一 ...

  10. zookeeper集群的搭建(三台相同)

    查看jdk java -version 卸载自带jdk rpm -qa|grep java rpm -e --nodeps tzdata-java-2015e-1.el6.noarch rpm -e ...