hide handkerchief
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 |
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的更多相关文章
- 【HDOJ】2104 hide handkerchief
Problem Description The Children’s Day has passed for some days .Has you remembered something happen ...
- HDU 2104 hide handkerchief
题解:由题目可以知道,如果n和m的最大公约数不为1,那么总有箱子是无法遍历的,所以求一遍GCD就可以判断了. 注意点:一定要记住判断是==,在做题时又忘了. #include <cstdio&g ...
- hide handkerchief(hdu2104)
思考:这种找手绢就是,在判断是否互质.用辗转相除法(用来求最大公约数:a)进行判断.r=a%b;a=b;b=r;循环限制条件:除数b=0是结束除法.如果这时被除数a=1,则表示两个互质. #inclu ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- HOJ———丢手绢
hide handkerchief Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2104(判断互素)
hide handkerchief Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- #C++初学记录(遍历)
hide handkerchief Problem Description The Children's Day has passed for some days .Has you remembere ...
- 数学--数论--HDU 2104 丢手绢(离散数学 mod N+ 剩余类 生成元)+(最大公约数)
The Children's Day has passed for some days .Has you remembered something happened at your childhood ...
- 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 ...
随机推荐
- taglib简介
在 JSP最佳实践的 上一期,您学习了一种基于scriptlet的技术,这种技术被用来将上次修改的时间戳添加到JavaServer Page(JSP)文件中.不幸的是,比起它所提供的短期利益,scri ...
- 1F - A+B for Input-Output Practice (III)
Your task is to Calculate a + b. Input Input contains multiple test cases. Each test case contains a ...
- suricata 原文记录
如何在 Linux 系统上安装 Suricata 入侵检测系统 编译自:http://xmodulo.com/install-suricata-intrusion-detection-system-l ...
- C++/CLI学习入门
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxIAAAFlCAYAAAB/fN6bAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw
- [Robot Framework] Robot Framework用Execute Javascript对XPath表示的元素执行scrollIntoView操作
有些元素需要通过滚动条滚动才能变得可见. 如果这些元素在DOM结构里面存在,可以通过scrollIntoView让其可见,但如果在DOM结构里面不存在那就要通过拖动滚动条让其变的可见. Execute ...
- [ASP.NET]使用Oracle.ManagedDataAccess的OracleParameter参数化和OracleDataAdapter模糊查询
今天写个查询员工的信息的demo遇到了2个问题 问题1.使用Oracle.ManagedDataAccess的OracleParameter参数化 OracleParameter 的使用(参数名要以: ...
- Java语法基础课 动手动脑
1.枚举类型 它的每个具体值都引用一个特定的对象.相同的值则引用同一个对象. 枚举类型不是java原有数据类型 2.为什么double类型的数值进行运算得不到“数学上精确”的结果? 我们给出的数值,在 ...
- 透过摩拜和ofo,看产品从0到1时如何取舍需求(转)
大纲 背景介绍 从0至1,我们成功的关键是什么? 从0到1,我们为什么选择做?又为什么选择不做? 从0到1,我们面临什么选择?我们作出了什么选择? 从0到1,我们为什么作出了这种选择? 背景 在资本注 ...
- Linux服务器上新增开放端口号
开放端口的方法: 方法一:命令行方式 1. 开放端口命令: /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT ...
- Eclipse创建Dynamic Web部署
Eclipse创建Dynamic Web部署 http://blog.csdn.net/sweblish/article/details/6686046 Eclipse3.x中热部署项目,启动错误问题 ...