zoukankan      html  css  js  c++  java
  • 2016huasacm暑假集训训练四 数论_A

    题目链接:https://vjudge.net/contest/125308#problem/F

    题意:狼捉兔子,兔子躲在n个洞中一个,这n个洞围成一个圈,狼会从第0号洞开始,搜索隔m的洞,一直搜索下去,问是否存在洞另狼永远搜索不到,这样兔子就重获新生。
    刚开始没有思路,就瞎画了八个洞的图,然后m从1—7去找 发现只要 m能够整除n   就能活 也就是是求输入的两个数是否互质即最大公约数是否为1.为1不能活
    AC代码:
     1 import java.io.BufferedReader;
     2 import java.io.IOException;
     3 import java.io.InputStream;
     4 import java.io.InputStreamReader;
     5 import java.io.PrintWriter;
     6 import java.util.StringTokenizer;
     7 
     8 public class Main {
     9     public static void main(String[] args) {
    10 
    11         InputReader s = new InputReader(System.in);
    12         PrintWriter cout = new PrintWriter(System.out);
    13         int t , x, y, t1 ;
    14         t  =   s.nextInt();
    15         while (t-- > 0) {
    16             x = s.nextInt();
    17             y = s.nextInt();
    29             t1 = gcd(x,y);
    30             if(t1!=1)
    31             System.out.println("YES");
    32             else System.out.println("NO");
    33         }
    34         cout.flush();
    35     }
    36 
    37     static int gcd(int a, int b) {
    38         return b == 0 ? a : gcd(b, a % b);
    39     }
    40 }
    41 
    42 class InputReader {
    43 
    44     public BufferedReader rea;
    45     public StringTokenizer tok;
    46 
    47     public InputReader(InputStream stream) {
    48         rea = new BufferedReader(new InputStreamReader(stream), 32768);
    49         tok = null;
    50     }
    51 
    52     public String next() {
    53         while (tok == null || !tok.hasMoreTokens()) {
    54             try {
    55                 tok = new StringTokenizer(rea.readLine());
    56             } catch (IOException e) {
    57                 throw new RuntimeException(e);
    58             }
    59         }
    60         return tok.nextToken();
    61     }
    62 
    63     public int nextInt() {
    64         return Integer.parseInt(next());
    65     }
    66 
    67 }
     
  • 相关阅读:
    [概率论]2017.5.9
    [概率论] 2017 5.2
    [离散数学II]2017.5.2
    [离散数学II]2017.4.25
    [概率论]2017.4.19
    [概率论] 2017.4.18
    [离散数学II]2017.4.18
    [离散数学II]2017.4.11
    [概率论]2017.4.12
    [概率论]2017.4.5
  • 原文地址:https://www.cnblogs.com/LIUWEI123/p/5743542.html
Copyright © 2011-2022 走看看