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

题意:狼捉兔子,兔子躲在n个洞中一个,这n个洞围成一个圈,狼会从第0号洞开始,搜索隔m的洞,一直搜索下去,问是否存在洞另狼永远搜索不到,这样兔子就重获新生。
刚开始没有思路,就瞎画了八个洞的图,然后m从1—7去找 发现只要 m能够整除n 就能活 也就是是求输入的两个数是否互质即最大公约数是否为1.为1不能活
AC代码:
 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer; public class Main {
public static void main(String[] args) { InputReader s = new InputReader(System.in);
PrintWriter cout = new PrintWriter(System.out);
int t , x, y, t1 ;
t = s.nextInt();
while (t-- > ) {
x = s.nextInt();
y = s.nextInt();
t1 = gcd(x,y);
if(t1!=)
System.out.println("YES");
else System.out.println("NO");
}
cout.flush();
} static int gcd(int a, int b) {
return b == ? a : gcd(b, a % b);
}
} class InputReader { public BufferedReader rea;
public StringTokenizer tok; public InputReader(InputStream stream) {
rea = new BufferedReader(new InputStreamReader(stream), );
tok = null;
} public String next() {
while (tok == null || !tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(rea.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tok.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} }
 
05-08 15:51