转化为用欧几里得算法判断互质的问题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\),则利用的性 ...
随机推荐
- C#操作Office.word(一)
该文章主要是讲述如何使用VS2010创建word文档,因为在项目中我们可能需要点击一个按钮把数据库中的项目表单或图片显示到word文档中,因此该文章主要分析如何使用VS2010创建word文档并填写相 ...
- WCF服务
一.新建windows服务 二.新建wcf服务 三.添加安装程序 四.设置安装程序 五.设置启动代码 6 7 8. 注:当使用管理员身份 安装不成功时,可以使用vs自带的命令工具 ...
- html 表头固定
<div style="width: 100%; min-width: 300px; padding-right: 10px;"> <table style=&q ...
- Could not load type System.ServiceModel.Activation.HttpModule解决办法
等注册完成后网站就可以打开了. win2008下提示未能从程序集“System.ServiceModel, Version=3.0.0.0问题解决 在Windows Server 2008中的IIS服 ...
- Spark学习资料
1. 倾情大奉送--Spark入门实战系列 2. Spark GraphX: http://blog.csdn.net/bluejoe2000/article/details/44308167
- poj 2007 Scrambled Polygon 极角排序
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 retur ...
- Select specified items from Tuple List
#Select specified items from Tuple List ##Select one item to form list `tupleList.Select(element =&g ...
- cout输出各种进制
cout使用: int main(){ int a=10; cout<<"Dec:"<<a<<endl; cout<<hex&l ...
- 2014多校3 Wow! Such Sequence!段树
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4893 这个问题还真是纠结啊--好久不写线段树的题了.由于这几天学伸展树.然后认为线段树小case了. ...
- adb shell top
PID:进程在系统中的ID CPU% - 当前瞬时所以使用CPU占用率 #THR - 程序当前所用的线程数 UID - 运行当前进程的用户id Name - 程序名称android.process.m ...