最大公约数

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的洞口进入,再从第m个洞口进入,问狼能否吃到兔子,如果可以输出“YES”,否则输出“NO”.
 
 
分析:此题为最大公约数,如果gcd(m,n)==1,则狼就能吃到兔子。 
 
 
 
 
代码如下:
 
 
 
 
 
 
#include <iostream>
#include <cstdio> using namespace std;
unsigned int gcd(unsigned int a,unsigned int b)
{
return b==0? a:gcd(b,a%b);
}
int main()
{
int t;
unsigned int m,n;
scanf("%d",&t);
while(t--)
{
scanf("%u%u",&m,&n);
if(gcd(m,n)==1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}

最大公约数——Program G的更多相关文章

  1. eclipse: Program "g++" not found in PATH

    gdb命令行调试虽然还行,但是确实不如图形界面的直观...个人还是不习惯,就开始鼓捣eclipse的c/c++IDE(VS2013安装需要IE10,蛋疼,懒得弄) Build一个C工程的时候报错.我安 ...

  2. eclipse CDT Error: Program "g++" not found in PATH

    右击project explore ->properties-  >c/c++ build->environment , 设置 mingw_home 路径

  3. C++扬帆远航——14(求两个数的最大公约数)

    /* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:gongyueshu.cpp * 作者:常轩 * 微信公众号:W ...

  4. NOI上看到的几个小学奥数

    :余数相同问题 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 已知三个正整数 a,b,c. 现有一个大于1的整数x,将其作为除数分别除a,b,c,得到的余数相同 ...

  5. CentOS搭建NodeJS环境

    事件驱动,承受高并发……这些耀眼的光环,使前端开发者不能不去学习NodeJS. 今天就在开发环境把NodeJS搭建起来了. 1. 下载node wget http://nodejs.org/dist/ ...

  6. Scala编程--函数式对象

    本章的重点在于定义函数式对象,也就是说,没有任何可变状态的对象的类.作为运行的例子,我们将创造若干把分数作为不可变对象建模的类的变体.在这过程中,我们会展示给你Scala面向对象编程的更多方面:类参数 ...

  7. Node.js入门:Node.js&NPM的安装与配置

    Node.js安装与配置      Node.js已经诞生两年有余,由于一直处于快速开发中,过去的一些安装配置介绍多数针对0.4.x版本而言的,并非适合最新的0.6.x的版本情况了,对此,我们将在0. ...

  8. ORA-12545: 因目标主机或对象不存在, 连接失败

    ORA-12545: 因目标主机或对象不存在, 连接失败 1. 问题描述 XP系统下同时安装了AX1应用程序和升级版AX2,连接同一个在本机Oracle客户端上配置的连接实例,其中AX2显示链接成功, ...

  9. rdynamic和-whole-archive

    遇到如下情况,主程序通过dlopen来打开.so文件,但是.so用到了主程序的log函数. 编译so时,通过引用主程序头文件来编译通过,头文件有log函数声明: extern "C" ...

随机推荐

  1. 转:C/C++基本数据类型所占字节数

    参考:http://blog.csdn.net/vast_sea/article/details/8076934 关于这个基本的问题,很早以前就很清楚了,C标准中并没有具体给出规定那个基本类型应该是多 ...

  2. jquery的tree table(树表)

    因项目需要,需要在表格中加入tree,使用了jquery的tree table,经美化,完美兼容各种框架的table: 请移步下载tree table 的js文件及css文件等,http://ludo ...

  3. mybatis动态sql中where标签的使用

    where标记的作用类似于动态sql中的set标记,他的作用主要是用来简化sql语句中where条件判断的书写的,如下所示: <select id="selectByParams&qu ...

  4. OpenGL的gluLookAt观察变换函数详解

    void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,                          GLdouble center ...

  5. 利用SecureCRT上传、下载文件(使用sz与rz命令),超实用!

    利用SecureCRT上传.下载文件(使用sz与rz命令),超实用! 文章来源:http://blog.csdn.net/dongqinliuzi/article/details/39623169 借 ...

  6. Windows高精度时间

    目录 第1章计时    1 1.1 GetTickCount    1 1.2 timeGetTime    1 1.3 QueryPerformanceCounter    1 1.4 测试     ...

  7. 解决PhoneGap不支持viewport的几种方法

    前几天用phonegap编译GameBuilder+CanTK时,发现HTML里的viewport无效.CanTK根据devicePixelRatio检测设备的DPI,然后用viewport设置正确的 ...

  8. html5中的表单

    <form id="aForm" action="reg.php"> <p>请填写表单内容以完成注册!</p> <fi ...

  9. linux笔记:目录处理命令ls,mkdir,cd,pwd,rmdir,cp,mv,rm

    linux命令的格式:命令 [-选项] [参数]例:ls -la /etc 命令:ls命令所在路径:/bin/ls功能:显示目录文件用法:ls [-aldh] []参数:-a 查看所有文件,包括隐藏文 ...

  10. hdu 1026 Ignatius and the Princess I (bfs+记录路径)(priority_queue)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1026 Problem Description The Princess has been abducted ...