转化为用欧几里得算法判断互质的问题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\),则利用的性 ...
随机推荐
- LOJ 1341 Aladdin and the Flying Carpet(质因子分解)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给两个数a,b,求满足c * d = a且c>=b且d>=b的 ...
- tmod命令
tmod ./tpl --debug --no-watch --output ./tplbuild
- linux文件系统操作——底层文件访问
在不使用标准I/O的情况下,使用write,read,open实现对文件的复制操作,这些调用都是直接使用底层系统调用,完成从用户代码到内核代码的切换,消耗大量的系统资源,今天对此进行研究主要是 ...
- Vmware虚拟机时间不准问题
测试程序时碰到虚拟机经常时间不准,深受困扰,后来发现虚拟机有一个设置可以同步虚拟机和宿主机的时间: 该功能需要vmware tools安装成功才能有效.vmware tools的安装就不多细说了,至于 ...
- MVC-05 Model(1)
在开发应用程序的过程中,经常需要处理许多大大小小的数据,例如,SQL Server数据库存取.连接AD(Active Directory)数据库进行验证.调用外部Web Service取得数据等.除了 ...
- ORACLE模拟一个数据文件坏块并使用RMAN备份来恢复
1.创建一个实验用的表空间并在此表空间上创建表 create tablespace blocktest datafile '/u01/oradata/bys1/blocktest.dbf' size ...
- BZOJ 1739: [Usaco2005 mar]Space Elevator 太空电梯
题目 1739: [Usaco2005 mar]Space Elevator 太空电梯 Time Limit: 5 Sec Memory Limit: 64 MB Description The c ...
- Dating with girls(1)(二分+map+set)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu5115 Dire Wolf【区间dp】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4361169.html ---by 墨染之樱花 [题目链接]http://acm.hdu.e ...
- C# ikvm 运行htmlunit Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found
在使用 ikvm 去运行 htmlunit 中的 webclient Getpage的时候 报错说com.sun.org.apache.xerces.internal.jaxp.DocumentBu ...