质数问题.

#include<bits/stdc++.h>
#define deg(a) cout<<#a<<'='<<a<<"\n"
#define de(a) cout<<#a<<'='<<a<<' '
#define all(a) a.begin(),a.end()
#define af1(x,a) for(int x=1;x<=a;x++)
#define af0(x,a) for(int x=0;x<a;x++)
#define af(x,z,a) for(int x=z;x a;x++)
#define ff first
#define ss second
#define pii pair<int ,int>
#define vvint vector<vector<int>>
const int N = 1e6+10,INF=0x3f3f3f3f;
using namespace std;
int a[2007],s=0,b[5007];
bool mp[5000];//是质数就存表,防止重复check浪费时间;
bool check(int m){
	for(int x=2;x<=sqrt(m);x++){
		if(m%x==0)return false;
	}
	return true;
}//检测是否为质数;
void shai(){
	for(int x=2;x<=2000;x++){
		if(check(x)){
			mp[x]=true;
			a[s]=x;
			s++;
		}
	}
}//筛选2000内的质数;
void solve() {
	int n,k;
	cin>>n>>k;
	if(b[n]>=k)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	int t = 1;
	cin >> t;
	memset(mp,false,sizeof mp);
	shai();
	memset(b,0,sizeof b);
	af0(x,s-1){
	if(mp[a[x]+a[x+1]+1]){
		b[a[x]+a[x+1]+1]=1;
	}
	}
	af1(x,2008){
		b[x]+=b[x-1];
	}//差分可求各个位置前的满足情况的质数数量;
	while (t--) {
		solve();
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值