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 }
  • 相关阅读:
    golang 用tar打包文件或文件夹
    golang 最和谐的子序列
    golang 轮训加密算法
    golang map
    golang 队列
    golang 栈操作
    golang 多维数组
    golang 数组反转
    c# sendmessage control to scroll
    c# 启动的时候向其他程序传值
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4702052.html
Copyright © 2011-2022 走看看