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. Android开发之使用SwipeRefreshLayout完成下拉刷新

    SwipeRefreshLayout是V4包下的一个组件,老版本的V4包不支持这个组件功能.因此,如果发现自己的项目中无法导入SwipeRefreshLayout的包,那么说明项目中的V4包是老版本的 ...

  2. fedora25的nfs文件系统搭建

    关于NFS的原理介绍可以参考这篇文章:http://blog.51cto.com/atong/1343950 1> nfs服务端 安装nfs工具包和rpcbind包 dnf install nf ...

  3. iOS8 UIAlertView键盘闪一下的问题

    if (SYSTEM_VERSION >= 8.0) { UIAlertController *alertCtrl = [UIAlertController alertControllerWit ...

  4. post方式发送请求报文

    $url="http://www.test.com/04_demo_weather.php?id=5"; $ci=curl_init($url); curl_setopt($ci, ...

  5. [Robot Framework] Robot Framework里面的变量怎么知道是在哪里定义的?

    看变量在哪里定义的:Ctrl+Alt+Space

  6. Spring PropertyResolver 占位符解析(一)API 介绍

    Spring PropertyResolver 占位符解析(一)API 介绍 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html ...

  7. 接口没添加@responseBody注解

    今天在重写springaop小demo时,发现调用接口时,可以在控制台上正常返回结果,但是页面报错,debug半天,可以看到是调用了modelview的时候出错,找不到视图了.. debug的时候控制 ...

  8. [ES]elasticsearch章1 ES各角色的分工

    es集群里的master node.data node和client node到底是怎么个意思,分别有何特点? master节点 主要功能是维护元数据,管理集群各个节点的状态,数据的导入和查询都不会走 ...

  9. 搭建java环境和java学习

    https://blog.csdn.net/fishe_r/article/details/18863447 其中的 java配置文件用: { "shell_cmd": " ...

  10. openssl编译安装-各种蛋疼

    arm平台  ubuntu Linux xxxxxx 3.0.62 #2 PREEMPT Tue Apr 2 20:14:12 CST 2013 armv7l armv7l armv7l GNU/Li ...