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 ...
随机推荐
- 10.8H5日记
1.网页中去滚动条的属性 overflow:hidden: overflow-x:hidden:水平超出隐藏 2.z-index 层次叠加 元素重叠 谁的值大谁就在上边 当 当前元素有float和父级 ...
- mybatis入门--mybatis和hibernate比较
mybatis和hibernate的比较 Mybatis和hibernate不同,它不完全是一个ORM框架,因为MyBatis需要程序员自己编写Sql语句,不过mybatis可以通过XML或注解方式灵 ...
- sql重复数据的过滤问题
有重复数据主要有一下几种情况: 1.存在两条完全相同的纪录 这是最简单的一种情况,用关键字distinct就可以去掉 example: select distinct * from table(表名) ...
- LibreOJ #2006. 「SCOI2015」小凸玩矩阵 二分答案+二分匹配
#2006. 「SCOI2015」小凸玩矩阵 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- ipv6地址累加函数
#include <stdio.h> #include <arpa/inet.h> int main() { int i; int ret; struct in6_addr a ...
- [Selenium Grid] 搭建Hub和Node环境
Note : 先在Hub和Node的机器上安装好JDK, IE浏览器,Chrome浏览器,Firefox浏览器 准备好红色框标示的东西: Hub.bat :启动Hub AllNodes.bat : ...
- 最新Dashboard设计实例、技巧和资源集锦,视觉和功能两不误,妥妥的!
Dashboard设计,尽管设计师们叫法各不相同(例如:“数据面板设计”, “控制面板设计”, “仪表盘设计”或“后台界面设计”等等).但,此类设计的最终目都是力求以最直观.最简洁的方式呈现各种信息和 ...
- Photoshop零基础教程集锦,助你快速进阶为大佬,轻松、任性!!!
现今,对于Web或App UI设计师而言,除了不断学习专业知识,提升设计技能.掌握一款得心应手的设计工具(例如设计师们常用的图像处理工具PhotoShop,矢量图绘制工具AI, 图形视频处理工具AE, ...
- 室内设计类网站Web原型制作分享——Dinzd
Dinzd是一家德国室内设计网站,网站内涵盖全球设计精品资讯以及优秀案列.网站布局简单直观,内容丰富. 此原型模板所用到的交互动作有结合弹出面板做下拉菜单效果,鼠标按下文字按钮跳转页面,按钮hover ...
- c++11 时间相关操作练习
博客和书籍资料 来自该地址 https://www.cnblogs.com/qicosmos/category/490693.html 自行编写相应代码进行学习 // TimeTest.cpp: 定义 ...