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-1个人去遍历n个人 转换为 m与n 是否互质

#include <cstdio>
int gcd(int n, int m)
{
int r;
while (m)
{
r = n%m;
n = m;
m = r;
}
return n;
}

int main()
{
int n, m;
while (scanf_s ("%d%d", &n, &m) && n != -1 || m != -1)
{
if (gcd(n, m) == 1)
printf("YES\n");
else
printf("POOR Haha\n");
}
return 0;

最新文章

  1. mybatis_开发篇
  2. pandas.DataFrame排除特定行
  3. 使用SqlDataReader和SqlDataAdapter的注意
  4. 模拟淘宝登录和购物车功能:使用cookie记录登录名,下次登录时能够记得上次的登录名,使用cookie模拟购物车功能,使用session记住登录信息并验证是否登录,防止利用url打开网站,并实现退出登录功能
  5. ehcache memcache redis 三大缓存男高音
  6. 【mybatis】之批量添加
  7. &lt;c:forEach&gt; 详解
  8. 【HDOJ】4261 Estimation
  9. C# 获取一个独一无二的字符串 GUID
  10. Node.js NPM 使用介绍
  11. Hibernate超简单多表操作
  12. go语言中使用defer、panic、recover处理异常
  13. Vue一个案例引发「内容分发slot」的最全总结
  14. python 操作系统模块 -- OS
  15. Mybatis的类型处理器
  16. Effective C++ —— 实现(五)
  17. update-alternatives命令详解
  18. 如何调试nRF5 SDK
  19. 数组sort()方法排序
  20. 洛谷P4198 楼房重建 (分块)

热门文章

  1. String的所有方法以及解释
  2. 在centos7上安装Docker CE
  3. Laravel --- 【转】安装调试利器 Laravel Debugbar
  4. 系统学习 Java IO (十)----回退流 PushbackInputStream
  5. Java学习笔记——Socket实现文件传输
  6. Mysql索引优化之索引的分类
  7. charles使用说明(基于mac)
  8. 并发编程-Future+callable+FutureTask 闭锁机制
  9. Linux 运行jar包命令(Cent OS 7后台运行jar包)
  10. scrapy基础知识之防止爬虫被反的几个策略::