HDU 1222(数论,最大公约数)
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
Sample Output
程序分析:由上面的标题可以知道是求最最大公约数,但是一定不要超时,我有递归时间只用了0MS,其实这里我用了long long 型 ,其实没必要,int型也是可以的。还有我的if语句也是个出错点,就是因为这个答案一直不对。
程序代码:
#include<iostream>
#include<algorithm>
using namespace std;
#include<cstdio>
#define ll _int64
int gcd(int n,int m)
{ return m==?n:gcd(m,n%m); }
int main()
{
int T;
ll n,m,k;
cin>>T;
while(T--)
{
scanf("%I64d%I64d",&n,&m);
if(n<m)
swap(n,m);
k=gcd(n,m);
if(k==) cout<<"NO"<<endl; else cout<<"YES"<<endl; }
return ;
}
HDU 1222(数论,最大公约数)的更多相关文章
- HDU 1222 Wolf and Rabbit(gcd)
HDU 1222 Wolf and Rabbit (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- HDU 2503 (数论,最大公约数)
a/b + c/d Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1222 - Wolf and Rabbit & HDU 1108 - [最大公约数&最小公倍数]
水题,只是想借此记一下gcd函数的模板 #include<cstdio> int gcd(int m,int n){return n?gcd(n,m%n):m;} int main() { ...
- HDU 1222
题意: 一头狼和一头兔子在一座山中,给你一个数n表示洞的个数,编号从0~n-1.兔子可以随意躲在其中一个洞中,狼每次都从编号为0的洞出发,接下来走到第m个洞中,问兔子能不能活下来,即不被狼吃掉.例如: ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- hdu 1222 狼和兔子
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...
- (数论 最大公约数 最小公倍数) codeVs 1012 最大公约数和最小公倍数问题
题目描述 Description 输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数 条件: 1.P,Q是正整 ...
随机推荐
- java反编译命令javap
1. 输出所有类和成员 javap -private XX.class 2. 输出分解后的代码 javap -c XX.class
- 大数据技术 vs 数据库一体机[转]
http://blog.sina.com.cn/s/blog_7ca5799101013dtb.html 目前,虽然大数据与数据库一体机都很火热,但相当一部分人却无法对深入了解这两者的本质区别.这里便 ...
- Sublime 插件安装、常用配置
安装:sublime + 插件 安装Sublime: 官网:http://www.sublimetext.com/ 安装package control组件,之后我们会使用该组件给Sublime安装常用 ...
- Objective-C中NSArray和NSMutableArray的基本用法
/*---------------------NSArray---------------------------*/ //创建数组 NSArray *array1 = [NSArray arrayW ...
- hdu2554-N对数的排列问题
http://acm.hdu.edu.cn/showproblem.php?pid=2554 假设所有的2n个数据的位置分别从1~2n标号. 现在假设其中第ai个数据(双胞胎),和bi.那么他们的位置 ...
- curl向web服务器发送json数据
c++使用libcurl: /* *g++ demo.cpp -g -Wall -lcurl */ #include <string.h> #include <stdlib.h> ...
- 【踩坑】近来在Firefox上遇到的一些坑
因为工作一年多以来,做的工作基本都是和webkit系列打交道. 先是做m站,后来做了两个app内嵌的hybrid项目,从来只考虑webkit前缀和相关的伪类. 最近四个多月开始做内部的管理系统,写写样 ...
- 浅谈Servlet读取Html参数
1首先:webApp名称为cookieAndsession.html文件一般放在WebRoot文件夹下:/cookieAndsession/WebRoot/OrderForm.html,那么外界要访问 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- PHP冒泡排序法
冒泡排序(Bubble Sort),是一种计算机科学领域的较简单的排序算法.法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来. 冒泡排序它重复地走访过要排序的数列,一次比较两个元素,如果他 ...