🍑 OJ专栏
输入
3 5
15 20
63923 99999
输出
3 5 Good Choice
15 20 Bad Choice
63923 99999 Good Choice
🍑 题意
(x * step) % MOD,x 为变量,要求能得出 0~n-1的数
🍑 思路
🍤 结论:只要两个数互质,就是 good choice
⭐ 要使(第一次出现)(x * step) % MOD == 0 --> 此时:x*step = 最小公倍数 LCM(step,MOD)
🥚 0 <= x*step <= step*MOD 为一个周期,0 肯定会出现在 step*MOD 处
🥚 所以 LCM(step,MOD) == step*MOD 是最好的选择 (神奇,无证明)
⭐ 再由 LCM(step,MOD) * gcd(step,MOD) == step * MOD --> gcd(step,MOD) == 1
🙈 猜到了,又怎样,又给双换行坑了……
🍑 AC
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int a = sc.nextInt();
int b = sc.nextInt();
int res = gcd(a, b);
System.out.printf("%10d%10d", a, b);
if (res == 1)
{
System.out.println(" Good Choice");
} else
{
System.out.println(" Bad Choice");
}
System.out.println();
}
}
private static int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
}