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是正整 ...
随机推荐
- [LeetCode]题解(python):145-Binary Tree Postorder Traversal
题目来源: https://leetcode.com/problems/binary-tree-postorder-traversal/ 题意分析: 后序遍历一棵树,递归的方法很简单,尝试用非递归的方 ...
- poj 2689 大范围内素数筛选
/** 给定一定范围求其内的素数 注意: **/ #include <iostream> #include <math.h> #include <cstring> ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- JavaScript 反柯里化
浅析 JavaScript 中的 函数 uncurrying 反柯里化 柯里化 柯里化又称部分求值,其含义是给函数分步传递参数,每次传递参数后部分应用参数,并返回一个更具体的函数接受剩下的参数,这中间 ...
- MySQL 分区表各个分区的行数
分区的信息是记录在information_schema.partitions 这个表里的.它不能直接定位行所在的分区,但它可查到每个分区中有多少行. 例子: select partition_name ...
- JDK的目录结构及结构图
-bin目录: JDK开发工具的可执行文件 -lib目录: 开发工具使用的归档包文件 -jre: Java 运行时环境的根目录,包含Java虚拟机,运行时的类包和Java应用启动器, ...
- 《火球——UML大战需求分析》(0.1)——开篇废话
说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...
- java中File类详解
构造函数 代码如下: public class FileDemo { public static void main(String[] args){ //构造函数File(St ...
- linux中时间函数
linux下常用时间类型有四种: time_t . struct tm. struct timeval . struct timespec 1.time_t 时间函数 time_t ...
- Js闭包与循环
目标:点击任何一个li,提示当前点击位置 <ul> <li>第1个</li> <li>第2个</li> <li>第3个</ ...