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 ...
随机推荐
- SQL查询有两门以上不及格的学生及查询出全部及格的学生
1.表结构: /*学生*/ create table student( sno int not null primary key, sname ) ); /*课程*/ create table cen ...
- springboot添加fluent日志记录
istio默认会进行日志的记录,但是仅仅记录到服务.以及服务之间调用的信息,不记录业务日志. 如: 所以需要添加业务日志记录. 1.引入依赖 <dependency> <gr ...
- Liunx 硬盘分区
1)什么要进行硬盘分区:a) 更容易管理和控制系统,因为相关的文件和目录都放在一个分区中.b) 系统效率更高.c) 可以限制用户使用硬盘的份额(磁盘空间的大小).d) 更容易备份和恢复. 2)硬盘的逻 ...
- PAT 1087 有多少不同的值(20)(STL-set代码)
1087 有多少不同的值(20 分) 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x 的最大自然数 ...
- JVM 堆参数调优 (四)
堆参数调优 1.堆的结构 JAVA7 堆逻辑上分为:新生区.养老区.永久区:实际上堆只有新生区.养老区: Minor GC:轻量的垃圾回收: Major GC(Full GC):重量级垃圾回收. ...
- dpdk中文文档
Linux平台上DPDK入门指南 1. 简介 1.1. 文档地图 2. 系统要求 2.1. X86 上预先设置 BIOS 2.2. 编译DPDK 2.3. 运行DPDK应用程序 3. 使用源码编译DP ...
- MVC 第一章(下)
继续第一章 用Javascript and jQuery调用Web API 在上一节,我们用浏览器直接调用web API.但是大多数web API被客户端应用以编程的方式调用.那么我们写一个简单的ja ...
- day 3:注释,缩进
本节内容: 1,注释 2,缩进 1,注释: 使用#可以注释单行 # print("hello world") 三个双引号也可以注释多行 """ pri ...
- UI设计教程学习分享:APP布局
一.宫格布局 这种APP信息布局方式也是我们目前最常见的一种方式,也是符合用户习惯和黄金比例的设计方式,最知名的就是锤子手机的界面设计.锤子手机界面设计欣赏知名的APP设计采用的九宫格.六宫格等方式布 ...
- wait()和sleep()的区别
wait()是Object类的方法,当一个线程执行到wait()方法时,该线程就进入到一个和该线程相关的等待池中,同时释放了对象锁(暂时失去对象锁,wait(long timeout)超时时间到后还需 ...