HDU-1222

http://acm.hdu.edu.cn/status.php?first=&pid=&user=sunowsir&lang=0&status=0

题目描述:

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.

InputThe 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).

OutputFor 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题目思路:只需要判断m和n的最大公约数是否等于1即可,不等于一则永远抓不到;代码:/*************************************************************************    > File Name: HDU-1222.cpp    > Author: sunowsir ************************************************************************/

#include<bits/stdc++.h>using namespace std;

int gcd(int a,int b){    return b==0? a:gcd(b , a%b);}

int main(){    int m,n,N;    cin>>N;    while(N--){        cin>>m>>n;        if(gcd(m,n)!=1)  cout<<"YES"<<endl;        else  cout<<"NO"<<endl;    }    return 0;}
时间: 2024-10-01 04:38:38

HDU-1222的相关文章

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 (扩展欧几里德应用)

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(美素数)

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数. 给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一

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 狼和兔子

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

数论基础题目八题【欧几里得】【筛法素数】【中国剩余定理】

之前看的数论的知识,现在做几道题目找找感觉..... poj 1061 传送门 题目大意,给你x,y,m,n,L.代表青蛙a的坐标x,青蛙b的坐标y,青蛙a一次跳的距离m,青蛙b一次跳的距离n,以及mod的值L,求经过多少次跳相遇.即求:(m-n)*x0=(x-y)(mod L);  模线性方程的解,不过要注意处理,因为(m-n)和(x-y)有可能是负的,如果(m-n)是负的,则直接对俩数取负数,下面就是对 ((x-y)+L)%L. 然后就能用modular_linear_equation(LL

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU 3605 Escape 最大流+状压

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7145    Accepted Submission(s): 1553 Problem Description 2012 If this is the end of the

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201