zoukankan      html  css  js  c++  java
  • GCD(1222)Wolf and Rabbit

    Problem Description
    There is a hill with n holes around. The holes are signed from 0 to n-1.



    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
    The input starts with a positive integer P which indicates the number of test cases. Then on the following P lines,each line consists 2 positive integer m and n(0<m,n<2147483648).
     
    Output
    For each input m n, if safe holes exist, you should output "YES", else output "NO" in a single line.
     
    Sample Input
    2 1 2 2 2
     
    Sample Output
    NO YES
     
    Author
    weigang Lee
     
    Source
     
    Recommend
    Ignatius.L
     1 #include <stdio.h>
     2 #include <math.h>
     3 #include <queue>
     4 #include <vector>
     5 #include <stack>
     6 #include <map>
     7 #include <string>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <iostream>
    11 using namespace std;
    12 int gcd(int a,int b){
    13     return b==0?a:gcd(b,a%b);
    14 }
    15 int main()
    16 {
    17     int n,m,t;
    18     scanf("%d",&t);
    19     while(t--){
    20         scanf("%d%d",&n,&m);
    21         if(gcd(n,m)==1){
    22             printf("NO
    ");
    23         }
    24         else{
    25             printf("YES
    ");
    26         }
    27     }
    28     return 0;
    29 }
  • 相关阅读:
    sql limit 的用法
    浅谈XSS攻击
    python dns 服务器
    简单的文件上传下载服务器
    Linux下pyftplib简单的脚本
    浅谈optparse 解析命令行参数库
    爬虫下载脚本
    python 递归算阶乘 (转载)
    遍历目录及其子目录的文件
    Oracle数据导入导出
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4702052.html
Copyright © 2011-2022 走看看