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. Magento2 php商城在windows10上安装

    magento2 下载地址:https://github.com/magento/magento2/archive/develop.zip 参考地址: 版本要求 这个magento2  要选择好php ...

  2. OpenSource.SerializationLibrary

    1. Cap'n Proto protocol buffer的主要作者之一创建的新项目.其主页描述Cap'n Proto的性能比PB快很多. http://kentonv.github.io/capn ...

  3. 使用Tophat+cufflinks分析差异表达

    使用Tophat+cufflinks分析差异表达  2017-06-15 19:09:43     522     0     0 使用TopHat+Cufflinks的流程图 序列的比对是RNA分析 ...

  4. Java中创建对象的四种方法

    第一种 使用new关键字 第二种 使用反射技术:1)通过Class类的newInstance()方法:2)通过Constructor类的newInstance方法 第三种 通过Object类的clon ...

  5. boost asio 一个聊天的基本框架

    示例代码 #include "Util.h" #include "MyAsio.h" #include "TcpConnectionManager.h ...

  6. 使用JavaScript实现表现和数据分离

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...

  7. @Valid报错 No validator could be found for constraint

    使用hibernate validator出现上面的错误, 需要 注意 @NotNull 和 @NotEmpty  和@NotBlank 区别 @NotEmpty 用在集合类上面@NotBlank 用 ...

  8. spring学习 十五 spring的自动注入

    一  :在 Spring 配置文件中对象名和 ref=”id” ,id 名相同使用自动注入,可以不配置<property/>,对应的注解@Autowired的作用 二: 两种配置办法 (1 ...

  9. 如何安全管理windows系统日志,windows系统日志的报表和告警

    如何安全管理windows系统日志,windows系统日志的报表和告警 无论大小,每个拥有IT基础设施的组织都容易发生内部安全攻击.您的损失等同于黑客的收益:访问机密数据.滥用检索到的信息.系统崩溃, ...

  10. 728. Self Dividing Numbers

    class Solution { public: vector<int> selfDividingNumbers(int left, int right) { vector<int& ...