(hdu 2.2.4)Wolf and Rabbit(一个圆有n个数,每次数m个数,看能否遍历这个圆)

题目:

Wolf and Rabbit

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2021 Accepted Submission(s): 1146
 

Problem 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


Author

weigang Lee


Source

杭州电子科技大学第三届程序设计大赛


Recommend

Ignatius.L

题目分析:

这道题其实和http://blog.csdn.net/hjd_love_zzt/article/details/43194213 hdu step 1.2.2这道题是一模一样的,

只是把情景换一下而已。这道题实际抽象以下就是“一个圆有n个数,每次数m个数,看能否遍历这个圆” 。这实际上

判断一下n,m是否负责就行。判断互质的过程用到了求最大公约数的方法。

代码如下:

/*
 * c.cpp
 *
 *  Created on: 2015年2月2日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>

using namespace std;

int gcd(int a,int b){
	int temp;
	while(b != 0){
		temp = b;
		b = a%b;
		a = temp;
	}

	return a;
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,b;
		scanf("%d%d",&a,&b);
		if(gcd(a,b) == 1){
			printf("NO\n");
		}else{
			printf("YES\n");
		}
	}

	return 0;
}
时间: 2024-10-28 01:57:31

(hdu 2.2.4)Wolf and Rabbit(一个圆有n个数,每次数m个数,看能否遍历这个圆)的相关文章

hdu 2.2.4 Wolf and Rabbit 解题心得

原题: 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

HDU 1222 Wolf and Rabbit (扩展欧几里德应用)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6292    Accepted Submission(s): 3142 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

HDU 1222: Wolf and Rabbit

HDU 1222: Wolf and Rabbit ///@author Sycamore, ZJNU ///@accepted_on 2017-01-24 #include<iostream> using namespace std; unsigned gcd(unsigned a, unsigned b) { return b == 0 ? a : gcd(b, a % b); } int main() { int P; cin >> P; while (P--) { unsi

hdu 1222 Wolf and Rabbit (GCD)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5502    Accepted Submission(s): 2765 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

HDU-1222 Wolf and Rabbit (欧几里得定理)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7684    Accepted Submission(s): 3870 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1.

Wolf and Rabbit(gcd)

Wolf and Rabbit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5922    Accepted Submission(s): 2972点我 Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1

算法积累(字符串转换驼峰,判断一个字符串中那个字母出现次数最多,并且出现了几次)

因为算法比较烂,所以想做一下这方面的积累. 尽量能够每天学习一个新算法吧.(不过估计很悬) 好吧,今天第一个是字符串转换驼峰 直接上代码 var str = 'toupper-case'; var arr = str.split('-'); //toupper,case for (var i = 1; i < arr.length; i++) { //把除了第一个数组后面的数组的第一个值设置为大写然后大写字母和去掉第一个字符的剩下的字符进行拼合 arr[i] = arr[i].charAt(0)

输入一个有序数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字

输入一个有序数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字.如果有多对数字的和等于输入的数字,输出任意一对即可.例如输入数组1.2.4.7.11.15和数字15.由于4+11=15,因此输出4和11. 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void findTwo(int *array, int len, int sum) 5 { 6 int beg = 0; 7 int end = len-1; 8 int

编程题:已知一个一维数组a[10]中有10个数,求出第m个数到第n个数的和。其中m、n由键盘输入。

#include<stdio.h> int sum(int *q,int n) { int i,s=0; for(i=0;i<n;i++,q++) s+=*q; return s; } void main() { int n,m,a[10]={1,2,3,4,5,6,7,8,9,10}; int *p; printf("Please input m and n(m<n<10):\n"); scanf("%d,%d",&m,&am