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& ...
随机推荐
- Python入门必学:递归函数正确的操作使用方法,案例详解
递归函数,在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 举个例子,我们来计算阶乘n! = 1 x 2 x 3 x ... x n,用函数fact(n)表示,可以 ...
- Admin站点
使用admin站点 a.在settings.py中设置语言和时区 LANGUAGE_CODE = 'zh-hans' # 使用中国语言 TIME_ZONE = 'Asia/Shanghai' # 使用 ...
- TI C6000 优化进阶:循环最重要!
软件流水循环 1. C6000流水线(Pipeline) 一个指令的处理过程并不是一步完成,它被分为三个阶段:取指(Fetch).译码(Decode).执行(Excute).将每一个阶段放入独立的流程 ...
- 【转】Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本(一)
Oracle 的AWR 报告能很好的提供有关DB性能的信息. 所以DBA 需要定期的查看AWR的报告. 有关AWR报告的说明参考: Oracle AWR 介绍 http://blog.csdn.net ...
- poj3613:Cow Relays(倍增优化+矩阵乘法floyd+快速幂)
Cow Relays Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7825 Accepted: 3068 Descri ...
- git使用问题整理
git访问远端仓库报"fatal: Authentication failed for"错误的,可能原因是账户密码变更,git配置了使用creditial helper,所以需要取 ...
- Dsamain
TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 Windows Server 命令.参考和工具 Comm ...
- 设计模式之第3章-模板方法模式(Java实现)
设计模式之第3章-模板方法模式(Java实现) "那个,上次由于我老婆要给我做饭,所以就没有说完就走掉了...这个那个".这次和以前一样,先来开场福利(工厂方法模式已被作者踹下场) ...
- TortoiseSVN 同时检索多人的提交日志记录(如图操作)
- Python基础-week01 Python安装/变量/输入/及循环语句使用
一.Python介绍 (1).目前Python主要应用领域: 云计算: 云计算最火的语言, 典型应用OpenStack WEB开发: 众多优秀的WEB框架,众多大型网站均为Python开发,You ...