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 ...
随机推荐
- Eclipse中的maven项目搭建
一.eclipse中的maven设置 1.打开“首选项”----> "maven"---->"Installations".用来查看maven的使用 ...
- POJ2349 Arctic Network
原题链接 先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献. 显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除. 所以最后的答案就是 ...
- 百度云的ubuntu16.04.1部署Apache服务器+Django项目
使用Apache和mod_wsgi部署Django 是一种久经考验的将Django投入生产的方法. mod_wsgi是一个Apache模块,可以托管任何Python WSGI应用程序,包括Django ...
- h5 微信分享朋友和朋友圈
生成JS-SDK权限验证签名 实现发送给朋友和分享到朋友圈时内容参数自定义 一.微信JS-SDK 1. 获得Access Token access token的获得方法在前面有介绍,详情见 微信公众平 ...
- C#程序如何以管理员身份运行
VISTA 和 Windows 7 都使用了UAC来控制程序访问,对于一些需要使用管理员身份运行的程序就得右键以管理员身份运行. C# 编程中可以使程序自动使用管理员身份运行,也就是我们常常看到一些程 ...
- Delphi中静态方法重载还是覆盖的讨论
Delphi中静态方法重载还是覆盖的讨论 新人学习Delphi的时候,容易搞不懂的一个问题,当子类方法和基类方法同名,并且参数也一样的时候,叫做什么呢?是覆盖,还是重载呢? 答案是隐藏父类方法. 一般 ...
- UI设计教程分享:关于海报的合成过程
一张好的产品创意合成海报,能瞬间提升商品价值感,同时场景和相关元素的融入,让消费者瞬间明白商品属性及内涵.同时为商品营造的使用场景拥有更强的代入感,从而刺激转化.好的创意合成海报能为消费者带来视觉冲击 ...
- Linux 禁止root 用户登录启用sudo
1.添加sudo用户执行visudo命令,找到: 复制代码 代码如下: root ALL=(ALL) ALL 在下面增加:(注意,qianyunlai 是Linux新增的一个普通用户),没有的话可创建 ...
- 基于tomcat的solr环境搭建(Linux)
♥♥ solr是基于lucene的一个全文检索服务器,提供了一些类似webservice的API接口,用户可以通过http请求solr服务器,进行索引的建立和索引的搜索.索引建立的过程:用户提交的文 ...
- spring bean 生命周期和 ? 作用域? spirng bean 相互依赖? jvm oom ? jvm 监控工具? ThreadLocal 原理
1. spring bean 生命周期 1. 实例化一个bean ,即new 2. 初始化bean 的属性 3. 如果实现接口 BeanNameAware ,调用 setBeanName 4. Bea ...