码迷,mamicode.com
首页 > 其他好文 > 详细

F - 数论

时间:2016-08-05 21:08:23      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

F - 数论

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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


//题目意思是 有 0-N 个洞,0 和 N - 1 相连,狼从 0 洞开始,每 m 步进洞抓兔子,问是否有安全的洞,就是狼一直不会进去的洞存在

//就是看 m ,n 是否互质,互质就没有。

技术分享
 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 
 5 bool func(__int64 a,__int64 b)
 6 {
 7     __int64 temp;
 8     if (a<b)
 9     {
10         temp=a;
11         a=b;
12         b=temp;
13     }
14     __int64 c=a%b; 
15     while (c!=0)
16     {
17         c=a%b;
18         a=b;
19         b=c;
20     }
21     if (a==1) return 1;//huzhi
22     return 0;
23 }
24 
25 int main()
26 {
27     int t;
28     __int64 m,n;
29     scanf("%d",&t);
30     while (t--)
31     {
32         scanf("%I64d%I64d",&m,&n);
33         if (m==1||n==1)
34         {
35             printf("NO\n");
36             continue;
37         }
38 
39         if (m==2&&n==2)
40         {
41             printf("YES\n");
42             continue;
43         }
44 
45         if (func(n,m))
46         {
47             printf("NO\n");
48         }
49         else
50             printf("YES\n");
51     }
52     return 0;
53 }
View Code

 

 

F - 数论

标签:

原文地址:http://www.cnblogs.com/haoabcd2010/p/5742623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!