数据范围
1≤T≤30,
2≤n≤1000,
0≤k≤1000
输入样例:
5
27 2
45 7
2 0
15 1
17 1
输出样例:
YES
NO
YES
YES
YES
先用质数筛筛出质数,然后枚举一遍求前缀和就好
#include<cstdio>
#include<cstring>
#include<map>
#define ll long long
#define ri register int
using namespace std;
const int maxn = 2e5 + 7;
int mark[maxn];
int prime[maxn];
inline void orl(int n) {//欧拉筛
mark[1] = 1;
for (ri i = 2; i <= n; ++i) {
if (!mark[i]) {
prime[++prime[0]] = i;
}
for (ri j = 1; j <= prime[0]; ++j) {
int x = prime[j] * i;
if (x > n)break;
mark[x] = 1;
if (i % prime[j] == 0) {
break;
}
}
}
}
int sum[maxn];
map<ll, int > map1;
int main() {
orl(maxn-1);
for (int i = 2; i <= prime[0]; ++i) {
map1[prime[i]+prime[i-1]+1]=1;
}
for (int i = 2; i <= maxn - 1; ++i) {
if (map1[i]&&!mark[i])sum[i] = 1;
sum[i] += sum[i - 1];
}
int T;
scanf("%d" ,&T);
while(T--){
int n, k;
scanf("%d %d", &n, &k);
if (sum[n] >= k)printf("YES\n");
else printf("NO\n");
}
}