17A. Noldbach problem

本文探讨了Noldbach问题,即验证在指定范围内是否存在至少k个素数可以表示为两个相邻素数及1之和。通过预先计算素数及其组合,提供了一种高效的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Noldbach problem
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 57 + 1.

Two prime numbers are called neighboring if there are no other prime numbers between them.

You are to help Nick, and find out if he is right or wrong.

Input

The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).

Output

Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.

Examples
input
27 2
output
YES
input
45 7
output
NO
Note

In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.


给出n,问在[0-n] 区间内是否能找到K个数,要求这k个数都是素数且每个数都能写成三个数的的和,且这三个数中,一个是1,另外两个数是相邻的素数


素数打表+记录


#include<cstdio>
const int maxn=10000;
int prime[maxn],num[maxn*2],result[maxn*2];
void work()
{
	int a=0,b=2;
	for(int i=2;i<maxn;++i)
	{
		if(prime[i]==0)
		{
			if(i>2)
			{
				a=b;b=i;
				num[a+b+1]=1;
			}
			for(int j=2*i;j<maxn;j+=i)
			{
				prime[j]=1;
			}
		}
	}
	for(int i=2;i<maxn;++i)
	{
		if(prime[i]==0&&num[i]==1)
		{
			result[i]=1;
		}
		result[i]+=result[i-1];
	}
}
int main()
{
	work();
	int n,k;
	while(~scanf("%d%d",&n,&k))
	{
		printf("%s\n",result[n]>=k?"YES":"NO");
	}
	return 0;
} 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值