2015 HUAS Summer Trainning #6~G

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

解题思路:题目的意思是求两个数的最大公约数,如果最大公约数是1,那就输出NO,否则输出YES。这个题目没什么技巧,用一个while循环差不多就可以解决。

程序代码:

#include<stdio.h>
int F(int m,int n)
{
 int t;
 while(n%=m)//,n)
  t=m,m=n,n=t;
 return m;
}
int main()
{
 int m,n,k,t;
 scanf("%d",&t);
 while(t--)
 {
  scanf("%d%d",&m,&n);
  k=F(m,n);
  if(k==1)
   printf("NO\n");
  else
   printf("%YES\n");
 }
 return 0;
}

时间: 2024-07-30 18:39:42

2015 HUAS Summer Trainning #6~G的相关文章

2015 HUAS Summer Trainning #5~G

Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into t

2015 HUAS Summer Trainning #5 C

Description Let x and y be two strings over some finite alphabet A. We would like to transform x into y allowing only operations given below: Deletion: a letter in x is missing in y at a corresponding position. Insertion: a letter in y is missing in 

2015 HUAS Summer Training#2 G

题目: Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Far

2015 HUAS Summer Trainning #6~H

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

2015 HUAS Summer Trainning #4 B

Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so calledscribers. The scriber had been given a book and after several months he finished its copy. One of

2015 HUAS Summer Trainning #4 C

My birthday is coming up and traditionally I’mserving pie. Not just one pie, no, I have a numberN of them, of various tastes and of various sizes. Fof my friends are coming to my party and each ofthem gets a piece of pie. This should be one pieceof o

2015 HUAS Summer Trainning #4 D

Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the minimalamount of them, such they would completely cover the segment [0, M]. InputThe first line is the number of test cases, followed by a blank line.Eac

2015 HUAS Summer Trainning #5~E

Description The world financial crisis is quite a subject. Some people are more relaxed while others are quite anxious. John is one of them. He is very concerned about the evolution of the stock exchange. He follows stock prices every day looking for

2015 HUAS Summer Trainning #4 A

Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input seque