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& ...
随机推荐
- 第7章 数据库访问与ORM 慕课网微信小程序开发学习笔记
第7章 数据库访问与ORM https://coding.imooc.com/learn/list/97.html 目录: 7-1 数据库操作三种方式之原生SQL 19:09 7-2 从一个错误了解E ...
- Oracle redo与undo 第二弹
首先看一下undo与redo的字面意思: undo:撤销,也就是取消之前的操作. redo:重做,重新执行一遍之前的操作. 什么是REDO REDO记录transaction logs,分为o ...
- 2、python中的数字
第二篇开始谈谈python中的数据. 一.前言 python中的数字包含了整数.浮点数.复数三种.在python的早期版本,或许可以看到正数被分为长整数与短整数,后来被取消了,因此这里不作讨论.通常我 ...
- 最近使用Nginx的一点新得
1.基本的负载配置 Nginx最简单的配置模块如下 upstream name{ server ip:port; server ip:port; } server { listen 80; serve ...
- Linux下 导入导出数据库
1.怎么找到mysql下的bin? 1.1首先我在网上百度了一些Linux下如何导入导出数据.基本都是用mysqldump命令,但是如果没有到指定目录 下,执行这个命令是没有用的.一开始我还以为要在m ...
- TCP/IP网络编程之基于TCP的服务端/客户端(二)
回声客户端问题 上一章TCP/IP网络编程之基于TCP的服务端/客户端(一)中,我们解释了回声客户端所存在的问题,那么单单是客户端的问题,服务端没有任何问题?是的,服务端没有问题,现在先让我们回顾下服 ...
- Python中函数参数类型和参数绑定
参数类型 Python函数的参数类型一共有五种,分别是: POSITIONAL_OR_KEYWORD(位置参数或关键字参数) VAR_POSITIONAL(可变参数) KEYWORD_ONLY(关键字 ...
- 谈一谈Tomcat中webSocket,Jetty WebSocket 和Spring WebSocket以及github中Java-WebSocket.jar分别对Socket协议的角色定位以及效果的不同点;
开局先上一张图:(http://tomcat.apache.org/tomcat-7.0-doc/web-socket-howto.html) 当前截图来自于apache的tomcat官网(问:为 ...
- error LNK2001: unresolved external symbol ___CxxFrameHandler3
Q: VS2005编译的静态库, 在vc++6.0中连接出现错误 error LNK2001: unresolved external symbol ___CxxFrameHandler3 A: ...
- ajax提交表单,支持文件上传
当我们提交表单但是又不想要刷新页面的时候就可以考虑使用ajax来实现提交功能,但是这有个局限就是当有文件上传的时候是行不通的,下面借助于jquery.form可以很方便满足我们的需求. 1.表单写 ...