HDU1.2.3 hide handkerchief
2015-08-03 20:43
351 查看
最开始以为只是一道超级水的模拟题,但是用以下的模拟会超内存限制
但是也实在想不出什么方法,于是去百度了一发,得知其结论为M与N互质,但是证了好久还是证不来,看来自己数学功底真的不行!
既然知道了互质,那么就是欧几里得求最小公约数即可,代码如下:
#include <cstdio> #include <iostream> #include <cstring> using namespace std; bool a[100000001]; int main() { int N,M; scanf("%d%d",&N,&M); while(N!=-1&&M!=-1){ int temp=1; memset(a,0,sizeof(a)); while(a[temp]!=1){ a[temp]=1; temp+=M; temp=temp%(N+1)+1; } int flag=0; for(int i=1;i<=N;i++) if(a[i]==0){ flag=1; break; } if(flag) printf("POOR Haha\n"); else printf("YES\n"); scanf("%d%d",&N,&M); } return 0; }
但是也实在想不出什么方法,于是去百度了一发,得知其结论为M与N互质,但是证了好久还是证不来,看来自己数学功底真的不行!
既然知道了互质,那么就是欧几里得求最小公约数即可,代码如下:
#include <cstdio> #include <iostream> #include <cstring> using namespace std; int gcd(int m,int n) { if(m<n){ int temp=n; n=m; m=temp; } if(n==0) return m; else return gcd(n,m%n); } int main() { int N,M; scanf("%d%d",&N,&M); while(N!=-1&&M!=-1){ if(gcd(N,M)==1) printf("YES\n"); else printf("POOR Haha\n"); scanf("%d%d",&N,&M); } return 0; }
相关文章推荐
- linux查看系统状态命令
- Linux id 命令 - 显示用户id和组id信息
- PHP中的CURL
- Hdu 5307 He is Fly 2015ACM多校对抗赛第二场
- C++中cin和cin.getline函数连用的问题
- HTML5中File对象初探(转)
- 管理Linux文件权限和所有权
- 【HTTP】Http报文
- 以后在个人网站更新
- redis 系列文章推荐
- POJ1125Floyd-warshall算法模板题
- 剑指Offer面试题23(Java版):从上往下打印二叉树
- 关于Linux文件访问权限与设置用户id位
- UVA 1611 Crane 起重机 (子问题)
- Android开发之创建ContextMenu上下文菜单
- java中的url 编码与解码
- HDU1.2.2 Biker's Trip Odometer
- 理清Linux中的各种用户ID关系
- POJ 1129 Channel Allocation(染色)
- 【leetcode】Combination Sum III