转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit
Description
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
Output
Sample Input
1 2
2 2
Sample Output
YES
#include <stdio.h>
#define LL long long
LL gcd(int a, int b)
{
return (b == ) ? a : gcd(b, a%b);
}
int main()
{
bool flag;
LL t;
scanf("%lld", &t);
while(t--)
{
LL m, l;
flag = ;
scanf("%lld%lld", &m, &l);
if(gcd(m, l) == )
printf("NO\n");
else
printf("YES\n");
}
return ;
}
转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit的更多相关文章
- python常用算法(6)——贪心算法,欧几里得算法
1,贪心算法 贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以考虑,他所做出的的时在某种意义上的局部最优解. 贪心算法并不保证会得到最优解,但 ...
- 浅谈欧几里得算法求最大公约数(GCD)的原理及简单应用
一.欧几里得算法及其证明 1.定义: 欧几里得算法又称辗转相除法,用于求两数的最大公约数,计算公式为GCD(a,b)=GCD(b,a%b): 2.证明: 设x为两整数a,b(a>=b)的最大公约 ...
- C语言:互质
今天遇到一道奇怪的程序题,和平常的不同.同样都是互质,但是一般的题目都是判断两个数字是否互质,但这道题则是给定一个数字n,要求输出所有小于等于n的与n互质的数,题目已经在下面给出: 质数与互质概念不是 ...
- 扩展欧几里得算法(extgcd)
相信大家对欧几里得算法,即辗转相除法不陌生吧. 代码如下: int gcd(int a, int b){ return !b ? gcd(b, a % b) : a; } 而扩展欧几里得算法,顾名思义 ...
- 欧几里得算法与扩展欧几里得算法_C++
先感谢参考文献:http://www.cnblogs.com/frog112111/archive/2012/08/19/2646012.html 注:以下讨论的数均为整数 一.欧几里得算法(重点是证 ...
- ****ural 1141. RSA Attack(RSA加密,扩展欧几里得算法)
1141. RSA Attack Time limit: 1.0 secondMemory limit: 64 MB The RSA problem is the following: given a ...
- 关于欧几里得算法(gcd)的证明
求a,b的最大公约数我们经常用欧几里得算法解决,也称辗转相除法, 代码很简短, int gcd(int a,int b){ return (b==0)?a:gcd(b,a%b); } 但其中的道理却很 ...
- 浅谈扩展欧几里得算法(exgcd)
在讲解扩展欧几里得之前我们先回顾下辗转相除法: \(gcd(a,b)=gcd(b,a\%b)\)当a%b==0的时候b即为所求最大公约数 好了切入正题: 简单地来说exgcd函数求解的是\(ax+by ...
- 【算法】欧几里得算法与青蛙约会oj
欧几里得和扩展欧几里得算法 题目: poj 1061 poj 2142 双六 扩展欧几里得算法详解 先说欧几里得算法:欧几里得算法辗转相除求\(gcd\).求\(a.b\)的\(gcd\),则利用的性 ...
随机推荐
- Android adb 命令图解
做了这么长时间的开发与管理,在命令上总是自见则过,往往却忽视了在其命令上的分享过程,所以现在稍微有点时间就把 其命令的相关操作来简单的扫盲一番吧,也系统通过这种方式去授之以渔而不是鱼,好了,我以图解的 ...
- js常用的一些正则验证文本框
只允许输入数字和-onKeyUp="value=value.replace(/[^-\d]/g,'')" onafterpaste="value=value.replac ...
- mac上搭建svn服务器
1.terminal 执行svnadmin create 库地址/库名,生成的即为svn库根地址. 2.修改对应目录下conf/svnserve.conf文件: anon-access = read ...
- Android 开发笔记“调用.net webservice遇到的问题”
1.An exception occurred: org.ksoap2.SoapFault SoapFault - faultcode: 'soap:Server' faultstring: '服务器 ...
- A Byte of Python 笔记(4)控制流:if、for、while、break、continue
第6章 控制流 3种控制流语句-- if for while 默认pyhon使用ASCII码来解释程序的,默认不支持中文,需要在程序的第一行或者第二行声明编码.官方参考具体参考以下三种方式:1. ...
- python自学笔记(五)python文本操作
一.python自带方法 r:read 读 w:write 写 a:append 尾行追加 先命令行进入python后 >>>d = open('a.txt','w') #在对应路径 ...
- 指针和引用区别 C++
#include <iostream> using namespace std; int main(){ ; void cubeByPoint(int *);//指针传参声明 void c ...
- 帝国cms数据表详细说明
表 名 解释 phome_ecms_infoclass_news 新闻采集规则记录表 phome_ecms_infotmp_news 采集临时表 phome_ecms_news 新闻主数据记录表 ph ...
- Storm几篇文章
http://tianhailong.com/ http://www.cnblogs.com/panfeng412/archive/2012/07/02/storm-common-patterns-o ...
- Linux下安装VNC Server
操作系统centos6.5,在其之上安装vnc server,可利用windows上的vnc client远程登录. 1. 安装 yum install tigervnc-server.x86_64 ...