zoukankan      html  css  js  c++  java
  • F

    F - 数论

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    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


    //题目意思是 有 0-N 个洞,0 和 N - 1 相连,狼从 0 洞开始,每 m 步进洞抓兔子,问是否有安全的洞,就是狼一直不会进去的洞存在

    //就是看 m ,n 是否互质,互质就没有。

     1 #include <iostream>
     2 #include <stdio.h>
     3 using namespace std;
     4 
     5 bool func(__int64 a,__int64 b)
     6 {
     7     __int64 temp;
     8     if (a<b)
     9     {
    10         temp=a;
    11         a=b;
    12         b=temp;
    13     }
    14     __int64 c=a%b; 
    15     while (c!=0)
    16     {
    17         c=a%b;
    18         a=b;
    19         b=c;
    20     }
    21     if (a==1) return 1;//huzhi
    22     return 0;
    23 }
    24 
    25 int main()
    26 {
    27     int t;
    28     __int64 m,n;
    29     scanf("%d",&t);
    30     while (t--)
    31     {
    32         scanf("%I64d%I64d",&m,&n);
    33         if (m==1||n==1)
    34         {
    35             printf("NO
    ");
    36             continue;
    37         }
    38 
    39         if (m==2&&n==2)
    40         {
    41             printf("YES
    ");
    42             continue;
    43         }
    44 
    45         if (func(n,m))
    46         {
    47             printf("NO
    ");
    48         }
    49         else
    50             printf("YES
    ");
    51     }
    52     return 0;
    53 }
    View Code
     
  • 相关阅读:
    Chrome滚动条透明的问题
    JavaScript版的简单动画
    关于AS3的事件移除释疑
    JavaScript的Hook
    JavaScript正则表达式的零宽断言
    webgame开发中的文件解密
    GMIC2011:熊俊谈从数据看iOS移动应用开发
    世上最伟大的十个公式
    OS X Lion 正式版制作安装盘全新安装方法说明
    市面上VB.NET的书比较少,推荐一本,下载地址在下面!
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/5742623.html
Copyright © 2011-2022 走看看