hdu 2104(判断互素)
hide handkerchief
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3970 Accepted Submission(s): 1884
Children’s Day has passed for some days .Has you remembered something
happened at your childhood? I remembered I often played a game called
hide handkerchief with my friends.
Now I introduce the game to you.
Suppose there are N people played the game ,who sit on the ground
forming a circle ,everyone owns a box behind them .Also there is a
beautiful handkerchief hid in a box which is one of the boxes .
Then
Haha(a friend of mine) is called to find the handkerchief. But he has a
strange habit. Each time he will search the next box which is separated
by M-1 boxes from the current box. For example, there are three boxes
named A,B,C, and now Haha is at place of A. now he decide the M if equal
to 2, so he will search A first, then he will search the C box, for C
is separated by 2-1 = 1 box B from the current box A . Then he will
search the box B ,then he will search the box A.
So after three times
he establishes that he can find the beautiful handkerchief. Now I will
give you N and M, can you tell me that Haha is able to find the
handkerchief or not. If he can, you should tell me "YES", else tell me
"POOR Haha".
will be several test cases; each case input contains two integers N and
M, which satisfy the relationship: 1<=M<=100000000 and
3<=N<=100000000. When N=-1 and M=-1 means the end of input case,
and you should not process the data.
-1 -1
#include <stdio.h>
using namespace std;
int gcd(int a,int b){
return b==?a:gcd(b,a%b);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF,n!=-&&m!=-){
if(gcd(n,m)!=) printf("POOR Haha\n");
else printf("YES\n");
}
return ;
}
hdu 2104(判断互素)的更多相关文章
- hdu 2104
#include <iostream> using namespace std; int gcd(int a,int b) { return (b?gcd(b,a%b):a); } int ...
- hdu 1756(判断点是否在多边形中)
传送门 题解: 射线法判定点是否在多边形内部: AC代码: #include<iostream> #include<cstdio> #include<cmath> ...
- hdu 2108 Shape of HDU【判断多边形是否是凸多边形模板】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2108 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- [转载]HDU 3478 判断奇环
题意:给定n个点,m条边的无向图(没有重边和子环).从给定点出发,每个时间走到相邻的点,可以走重复的边,相邻时间不能停留在同一点,判断是否存在某个时间停留在任意的n个点. 分析: (1)首先,和出发点 ...
- hdu 1756 判断点在多边形内 *
模板题 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> ...
- HDU 2104 hide handkerchief
题解:由题目可以知道,如果n和m的最大公约数不为1,那么总有箱子是无法遍历的,所以求一遍GCD就可以判断了. 注意点:一定要记住判断是==,在做题时又忘了. #include <cstdio&g ...
- The Accomodation of Students HDU - 2444(判断二分图 + 二分匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 1272 判断所给的图是不是生成树 (并查集)
判断所给的图是不是生成树,如果有环就不是,如果没环但连通分量大于1也不是 find函数 用递归写的话 会无限栈溢出 Orz要加上那一串 手动扩栈 Sample Input6 8 5 3 5 2 6 4 ...
- hdu 1325 判断有向图是否为树
题意:判断有向图是否为树 链接:点我 这题用并查集判断连通,连通后有且仅有1个入度为0,其余入度为1,就是树了 #include<cstdio> #include<iostream& ...
随机推荐
- yii2 基本的增删改查
一:添加方法 1.1 使用成员属性的方式 save $user_name = $_POST['user_name']; $password = $_POST['password']; //实例化 $u ...
- SHELL脚本的常规命令
**shell脚本的执行方式: 方法一:首先赋予x权限,再输入相对路径或绝对路径,./testdot.sh或/root/shell/testdot.sh 方法二:sh testdot.sh(会新开一个 ...
- Python知识点进阶——生成器
生成器 为什么要将列表转化为迭代器? 因为列表太大的话用内存太大,做成迭代器可以节省空间,用的时候再拿出部分. 生成器是不会把结果保存在一个系列中,而是保存生成器的状态,在每次进行迭代时返回一个值,知 ...
- windows下CMD命令大全(仅供参考)
CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本)chcp 修改默认字符集chcp 936默认中文chcp 650011. appwiz.c ...
- Python While循环、运算符以及一些基础运用
1.循环语句 循环打印"人生苦短,我用python" while True: print("人生苦短,我用python") 利用While循环,打印1~10 c ...
- STM32的四种输出模式(转载)
1.普通推挽输出(GPIO_Mode_Out_PP): 使用场合:一般用在0V和3.3V的场合.线路经过两个P_MOS 和N_MOS 管,负责上拉和下拉电流. 使用方法:直接使用 输出电平 ...
- HDU - 5017 Ellipsoid(模拟退火)
题意 给一个三维椭球面,求球面上距离原点最近的点.输出这个距离. 题解 模拟退火. 把\(z = f(x, y)\)函数写出来,这样通过随机抖动\(x\)和\(y\)坐标就能求出\(z\). 代码 / ...
- 解决maven项目Invalid bound statement (not found)的方法
用IDEA 做的ssm 的maven项目,登陆时出现上图问题. 原因是它读取不到DevUserMapper.xml文件和取它xml文件,后面查询在编译好的文件中,xml文件并没有引入进来,这就是导致出 ...
- xgboost原理总结和代码展示
关于xgboost的学习推荐两篇博客,每篇看2遍,我都能看懂,你肯定没问题 两篇方法互通,知识点互补!记录下来,方便以后查看 第一篇:作者:milter链接:https://www.jianshu.c ...
- vs code 快捷键总结
返回上个光标:alt + ←列编辑模式:shift + alt + 鼠标左键