题解:P17733 [ICPC 2019 Xuzhou R] <3 numbers
:::info[题目分析]{open}
这个神秘的
- 质数,因为质数的因数只有它本身和
1 ,共2 个因数。 -
| 分析完毕,我们令 |
|---|
:::success[Code]
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline bool is (int x) { //试除法
if (x == 2) return 1; //特判
for (int i = 2; i * i <= x; i ++) {
if (x % i == 0) return 0;
}
return 1;
}
int main () {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
int T; cin >> T;
int l, r;
while (T --) {
cin >> l >> r;
ll len = r - l + 1; //区间长
if (len >= 100) { //精髓,特判掉区间长大于100的情况
puts("Yes");
continue;
}
ll ans = 0;
for (int i = l; i <= r; i ++) { //暴力枚举
if (i == 1 || is(i)) ans ++;
//注意可以为1
}
if (ans * 3 < len) { //乘法不至于损耗精度
puts("Yes");
}
else puts("No");
}
return 0;
}
:::