Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem
题面链接
http://codeforces.com/contest/17/problem/A
题面
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.
题意
问你在[2,n]里面是否至少有k个质数由1+两个相邻的素数组成呢?
题解
直接暴力模拟就好了嘛
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int pri[maxn],n,k;
void pre()
{
pri[0]=1,pri[1]=1;
for(int i=2;i<maxn;i++){
if(pri[i])continue;
for(int j=i+i;j<maxn;j+=i)
pri[j]=1;
}
}
int main()
{
pre();
scanf("%d%d",&n,&k);
int ans = 0;
for(int i=2;i<=n;i++){
if(pri[i])continue;
int flag = 0;
for(int j=2;j<i;j++){
if(pri[j])continue;
for(int k=j+2;k+j<=i;k++){
if(!pri[k]&&!pri[j]&&k+j==i-1)
flag = 1;
if(!pri[k])break;
}
}
if(flag)ans++;
}
if(ans>=k)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
Codeforces Beta Round #17 A - Noldbach problem 暴力的更多相关文章
- Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...
- Codeforces Beta Round #17 C. Balance DP
C. Balance 题目链接 http://codeforces.com/contest/17/problem/C 题面 Nick likes strings very much, he likes ...
- Codeforces Beta Round #17 A.素数相关
A. Noldbach problem Nick is interested in prime numbers. Once he read about Goldbach problem. It sta ...
- Codeforces Beta Round #13 E. Holes 分块暴力
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Des ...
- Codeforces Beta Round #2 C. Commentator problem 模拟退火
C. Commentator problem 题目连接: http://www.codeforces.com/contest/2/problem/C Description The Olympic G ...
- Codeforces Beta Round #37 B. Computer Game 暴力 贪心
B. Computer Game 题目连接: http://www.codeforces.com/contest/37/problem/B Description Vasya's elder brot ...
- Codeforces Beta Round #10 B. Cinema Cashier 暴力
B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...
- Codeforces Beta Round #17 C. Balance (字符串计数 dp)
C. Balance time limit per test 3 seconds memory limit per test 128 megabytes input standard input ou ...
- Codeforces Beta Round #17 D.Notepad 指数循环节
D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...
随机推荐
- java矩阵相乘的计算
package a123; import java.util.Scanner; public class a132 { public static void main(String args[]) { ...
- Jetty入门
Jetty的入门 一.开发环境 Eclipse 4.3.1 Maven 3.1 Jetty 9.0.6.v20130930 Jetty的下载地址: http://download.eclipse ...
- 给AOP的after函数使用原函数局部变量
引:AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 这里我们可以理解为在执行某函数时,要先执 ...
- java的四种引用,强弱软虚
1.利用软引用和弱引用解决OOM问题:用一个HashMap来保存图片的路径和相应图片对象关联的软引用之间的映射关系,在内存不足时,JVM会自动回收这些缓存图片对象所占用的空间,从而有效地避免了OOM的 ...
- SQL语句汇总(一)——数据库与表的操作以及创建约束
首先,非常感谢大家对上篇博文的支持,真是让本菜受宠若惊,同时对拖了这么久才出了此篇表示抱歉. 前言:此文旨在汇总从建立数据库到联接查询等绝大部分SQL语句.SQL语句虽不能说很多,但稍有时间不写就容易 ...
- 我的Linux随笔目录
现在整理博客的时间少了,大多是在用为知笔记收藏和整理,一次集中发点Linux相关随笔整理和一个目录,是按时间顺序来的.每一篇都是自己用过之后整理的,应用场景已经尽可能的说明了,不明白的可以Q我,上班时 ...
- Dynamic CRM 2013学习笔记(二十五)JS调用web service 实现多条记录复制(克隆)功能
前面介绍过如何克隆一条当前的记录: Dynamic CRM 2013学习笔记(十四)复制/克隆记录 , 主要是通过界面上加一个字段,单击form上的clone 按钮时,改变这个字段的值以触发插件来实现 ...
- ASP.NET MVC5 与EF6学习系列
最近学习使用MVC5和EF6,博客园搜索了一番,写下这篇文章记录,以便学习使用. 一.ASP.NET MVC5 网站开发 @洞庭夕照写的博客系列 ASP.NET MVC5 网站开发实践 - 概述 AS ...
- Objective-C入门
厂长最近又有新计划,准备做iOS上的开发,要操作工们(其实就是我自己)学习Objective-C,准备为厂子下一步的发展做出巨大贡献.拿人钱财,替人消灾,又得花时间折腾一门语言.话说自从来到现车间,用 ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...