Noldbach problem
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 = 5+ 7 + 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.
The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).
Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.
| input |
| 27 2 |
| output |
| YES |
| input |
| 45 7 |
| output |
| NO |
#include <iostream>
#include <cstdio>
#include <cmath> int isPrime(int n); //判断n是否是素数
void initPrime(int n); //将n以内的素数存到数组内 此处用1000即可 using namespace std;
int p[]; //存储2~1000之间的素数
int main()
{
int n, k, i, j, counter=;
cin >> n >> k;
initPrime();
for(i=; i<=n; i++) {
if(isPrime(i)==)
continue;
for(j=; p[j]<i; j++) {
if(p[j]+p[j+]+ == i){
counter++;
break;
}
}
}
if(counter < k)
cout << "NO" <<endl;
else
cout << "YES" <<endl;
return ;
} void initPrime(int n) {
int i, j = ;
for(i=; i<n; i++) {
if(isPrime(i)){
p[j++] = i;
}
}
} int isPrime(int n) {
int i;
for(i=; i<=(int)sqrt(n); i++) {
if(n%i == ) {
return ;
}
}
return ;
}
Noldbach problem的更多相关文章
- Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...
- cf17A Noldbach problem(额,,,素数,,,)
题意: 判断从[2,N]中是否有超过[包括]K个数满足:等于一加两个相邻的素数. 思路: 枚举. 也可以:筛完素数,枚举素数,直到相邻素数和超过N.统计个数 代码: int n,k; int prim ...
- CF17A Noldbach problem 题解
Content 若一个素数可以用比它小的相邻的两个素数的和加 \(1\) 表示,那么称这个素数为"好素数". 给定两个正整数 \(n,k\),问从 \(2\) 到 \(n\) 的好 ...
- Codeforces Beta Round #17 A.素数相关
A. Noldbach problem Nick is interested in prime numbers. Once he read about Goldbach problem. It sta ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
随机推荐
- mysql模拟插入数据表
由于测试或者学习需要,我们要经常向一个新建的数据表插入几百万行以上的数据来验证我们的一些想法,比如索引的合理构建,表字段类型的设计等等,下面跟大家演示如何往一个新建的数据表插入N多条数据. 1.新建一 ...
- Ubuntu14.04右键菜单添加Sublime 2打开选项
序 Ubuntu上安装Sublime的时候直接下载的压缩包(软件中心里没有找到Sublime),于是每次想用Sublime打开一个文件的时候就得先打开Sublime然后从File -> Open ...
- ORACLE集合常用方法
集合方法pl/sql预定义了在varray 和嵌套表实例上进行调用的方法.这些方法能在集合上执行一定的功能. EXISTS 该函数返回集合中第一个元素的索引,如果集合为空,返回NULL Collect ...
- inline-block布局方式
刚研究了一下inline-block布局方式 inline-block布局方式是一种比float浮动更优的一种布局方式. 一个超简单的demo html: <!doctype html> ...
- tokyocabinet安装日志(持续更新)
http://sourceforge.jp/projects/sfnet_tokyocabinet/releases/这个网站的最新tt和tc都在此1.下载tokyocabinethttp://sou ...
- Oracle EBS-SQL (INV-9):检查搬运单分配异常.sql
select h.request_number, l.line_number, msib.segment1 item_code, t.transacti ...
- Oracle EBS-SQL (CST-1):检查BOM历史成本查询(Average Cost).sql
select msi1.segment1 父件编码, msi1.description 父件描述, msi1.primary_u ...
- C链表之创建简单静态链表
C代码: #include<stdio.h> #include<stdlib.h> #include<malloc.h> //创建简单静态链表 typedef st ...
- linux内核--进程地址空间(一)
引言:现代操作系统提供了一种对内存的抽象概念,叫做虚拟存储器,它为每个进程提供了一个大的,一致的,和私有的地址空间.通过一个很清晰的机制,虚拟存储器提供了3个重要的能力: 1)它将主存看成是一个存储在 ...
- 基于Andoird 4.2.2的同步框架源代码学习——同步提供端
Android同步框架 同步(synchronization)允许用户将远程数据下载到新的设备上,同时将设备上的帐户数据上传到远端.同步还保证用户能够看到最新的数据. 开发者自然可以通过自己的方式来设 ...