310389: CF1826C. Dreaming of Freedom

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Dreaming of Freedomtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBecause to take away a man's freedom of choice, even his freedom to make the wrong choice, is to manipulate him as though he were a puppet and not a person.— Madeleine L'Engle

There are $n$ programmers choosing their favorite algorithm amongst $m$ different choice options. Before the first round, all $m$ options are available. In each round, every programmer makes a vote for one of the remaining algorithms. After the round, only the algorithms with the maximum number of votes remain. The voting process ends when there is only one option left. Determine whether the voting process can continue indefinitely or no matter how people vote, they will eventually choose a single option after some finite amount of rounds?

Input

The first line contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases.

Each test case consists of a single line containing two integers $n$ and $m$ ($1 \leq n, m \leq 10^6$) — the number of people and choice options respectively.

Output

For each test case output "YES" if the programmers will eventually choose a single option, and "NO" otherwise.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as a positive answer).

ExampleInput
5
3 2
4 2
5 3
1000000 1000000
1 1000000
Output
YES
NO
YES
NO
YES
Note

In the first example, there are $8$ ways people could vote: $\{1|1|1, 1|1|2, 1|2|1, 1|2|2, 2|1|1, 2|1|2, 2|2|1, 2|2|2\}$.

In cases $1$, $2$, $3$, and $5$, the programmers are left with the first algorithm, and in the remaining cases people are left with the second one, so the voting ends in one round in any case.

In the second example, the programmers could always vote $1|1|2|2$. Both algorithms have the maximum number of votes and remain for the next round, so the voting never ends.

Input

题意翻译

$n$ 个程序员要在 $m$ 个算法里选出最受欢迎的算法,每轮投票每个程序员都会在剩下的算法中选择一个。 在第一轮投票前,$m$ 种算法都可以选择;每轮投票后,只保留有最多票数的算法;只剩下一种算法时,选拔结束。请判断无论怎样投票选拔都会结束吗?

Output

题目大意:
题目描述了一个投票过程,有 n 个程序员从 m 个不同的算法中选择他们最喜欢的算法。在每一轮投票中,每个程序员为他们选择的一个剩余算法投票。每一轮结束后,只有得票数最多的算法会保留下来。当只剩下一个选项时,投票过程结束。需要判断投票过程是否可以无限期进行,还是无论人们如何投票,他们最终都会在有限的轮数后选择一个单一选项。

输入数据格式:
第一行包含一个整数 t(1 ≤ t ≤ 10^5)——测试用例的数量。
每个测试用例由一行组成,包含两个整数 n 和 m(1 ≤ n, m ≤ 10^6)——分别是人数和选择选项的数量。

输出数据格式:
对于每个测试用例,如果程序员最终会选择一个单一选项,输出 "YES",否则输出 "NO"。
每个字母可以以任何大小写形式打印(例如,YES, Yes, yes, yEs 都会被识别为肯定答案)。

例:
输入:
5
3 2
4 2
5 3
1000000 1000000
1 1000000

输出:
YES
NO
YES
NO
YES

注意:
在第一个例子中,有 8 种投票方式:{1|1|1, 1|1|2, 1|2|1, 1|2|2, 2|1|1, 2|1|2, 2|2|1, 2|2|2}。
在第 1、2、3 和 5 种情况下,程序员会选择第一个算法,而在其余情况下会选择第二个算法,所以无论如何投票都会在一轮后结束。
在第二个例子中,程序员总是可以投 1|1|2|2。两个算法都得到了最多的票数并保留到下一轮,所以投票永远不会结束。题目大意: 题目描述了一个投票过程,有 n 个程序员从 m 个不同的算法中选择他们最喜欢的算法。在每一轮投票中,每个程序员为他们选择的一个剩余算法投票。每一轮结束后,只有得票数最多的算法会保留下来。当只剩下一个选项时,投票过程结束。需要判断投票过程是否可以无限期进行,还是无论人们如何投票,他们最终都会在有限的轮数后选择一个单一选项。 输入数据格式: 第一行包含一个整数 t(1 ≤ t ≤ 10^5)——测试用例的数量。 每个测试用例由一行组成,包含两个整数 n 和 m(1 ≤ n, m ≤ 10^6)——分别是人数和选择选项的数量。 输出数据格式: 对于每个测试用例,如果程序员最终会选择一个单一选项,输出 "YES",否则输出 "NO"。 每个字母可以以任何大小写形式打印(例如,YES, Yes, yes, yEs 都会被识别为肯定答案)。 例: 输入: 5 3 2 4 2 5 3 1000000 1000000 1 1000000 输出: YES NO YES NO YES 注意: 在第一个例子中,有 8 种投票方式:{1|1|1, 1|1|2, 1|2|1, 1|2|2, 2|1|1, 2|1|2, 2|2|1, 2|2|2}。 在第 1、2、3 和 5 种情况下,程序员会选择第一个算法,而在其余情况下会选择第二个算法,所以无论如何投票都会在一轮后结束。 在第二个例子中,程序员总是可以投 1|1|2|2。两个算法都得到了最多的票数并保留到下一轮,所以投票永远不会结束。

加入题单

上一题 下一题 算法标签: