C. Dreaming of Freedom

C. Dreaming of Freedom
time limit per test2.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Because 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≤t≤105
) — the number of test cases.

Each test case consists of a single line containing two integers n
and m
(1≤n,m≤106
) — 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).

Example
inputCopy
5
3 2
4 2
5 3
1000000 1000000
1 1000000
outputCopy
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.

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		if (n == 1) {
			cout << "YES" << endl;
			continue;
		}
		int res = 1;
		for (int i = 2; i <= sqrt(n); i++)
			if (n % i == 0)
			{
				res = i;
				break;
			}
		if (res == 1) {
			if(n > m)
				cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
			if (res > m)cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值