F - 数论

Description

There is a hill with n holes around. The holes are signed from 0 to n-1. 



A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into the hole every m holes. For example, m=2 and n=6, the wolf will get into the holes which are signed 0,2,4,0. If the rabbit hides in the hole which signed 1,3 or 5, she will survive. So we call these holes the safe holes. 

Input

The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648). 

Output

For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line. 

Sample Input

2
1 2
2 2

Sample Output

NO
YES

题意:有一座环形山脉,山脉中一共有n个洞,编号为0~n-1,现在有一头狼,从编号为0的洞开始找兔子,每隔m个洞他就会进洞一次,直到回到起点,让你求兔子待在哪些洞中是安全的,如果这种洞存在就输出YES,否则输出NO
分析:我的想法是只要考虑有没有安全洞的情况,就将题目分成了两种情况,当n不为0时,只要m等于1那就没有安全洞存在(因为狼会将每个洞都遍历一遍),其他时候安全洞都是存在的;当n为1时,没有安全洞。但是好像不对,没弄懂。
参照别人的想法,本题的实质是判断两个数是否互质。这个也好理解

AC代码:
#include<iostream>
using namespace std; int main() { int t,m,n,k; cin>>t; while(t--) { cin>>m>>n; while(n!=0) { k=m%n; m=n; n=k; } if(m!=1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }







转载于:https://www.cnblogs.com/lbyj/p/5730819.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值