Content

若一个素数可以用比它小的相邻的两个素数的和加 \(1\) 表示,那么称这个素数为"好素数"。 给定两个正整数 \(n,k\),问从 \(2\) 到 \(n\) 的好素数个数是否 \(\geqslant k\)。

数据范围:\(2\leqslant n\leqslant 1000,0\leqslant k\leqslant 1000\)。

Solution

直接通过埃氏筛得到 \(1000\) 以内的素数,再通过直接暴力枚举预处理出 \(1000\) 以内的“好素数”,最后再遍历 \(2\) 到 \(n\) 求得这段区间以内“好素数”的数量,判断即可。

Code

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std; int n, k, ans, isprime[1007], primes[1007], goodprimes[1007]; int main() {
for(int i = 2; i <= 1000; ++i) isprime[i] = 1;
for(int i = 2; i <= 1000; ++i)
if(isprime[i]) {
primes[++primes[0]] = i;
for(int j = i * 2; j <= 1000; j += i)
isprime[j] = 0;
}
for(int i = 1; i <= primes[0]; ++i)
for(int j = 1; j < i - 1; ++j)
if(primes[i] == primes[j] + primes[j + 1] + 1) {
goodprimes[primes[i]] = 1;
break;
}
scanf("%d%d", &n, &k);
for(int i = 2; i <= n; ++i) {
if(ans == k) return printf("YES"), 0;
if(goodprimes[i]) ans++;
}
if(ans == k) return printf("YES"), 0;
printf("NO");
return 0;
}

CF17A Noldbach problem 题解的更多相关文章

  1. cf17A Noldbach problem(额,,,素数,,,)

    题意: 判断从[2,N]中是否有超过[包括]K个数满足:等于一加两个相邻的素数. 思路: 枚举. 也可以:筛完素数,枚举素数,直到相邻素数和超过N.统计个数 代码: int n,k; int prim ...

  2. Codeforces Beta Round #17 A - Noldbach problem 暴力

    A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...

  3. Noldbach problem

    Description Noldbach problem time limit per test: 2 seconds memory limit per test: 64 megabytes inpu ...

  4. POJ2826:An Easy Problem?!——题解(配特殊情况图)

    http://poj.org/problem?id=2826 题目大意:给两条线,让它接竖直下的雨,问其能装多少横截面积的雨. ———————————————————————————— 水题,看题目即 ...

  5. HDU 1016 Prime Ring Problem 题解

    Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ... ...

  6. HDU 4143 A Simple Problem 题解

    题目 For a given positive integer n, please find the saallest positive integer x that we can find an i ...

  7. UVA101 The Blocks Problem 题解

    题目链接:https://www.luogu.org/problemnew/show/UVA101 这题码量稍有点大... 分析: 这道题模拟即可.因为考虑到所有的操作vector可最快捷的实现,所以 ...

  8. [CF-GYM]Abu Tahun Mod problem题解

    前言 这道题比较简单,但我还是想了好一会 题意简述 Abu Tahun很喜欢回文. 一个数组若是回文的,那么它从前往后读和从后往前读都是一样的,比如数组\(\left\{1\right\},\left ...

  9. [NOIP模拟测试9]题(Problem) 题解 (组合数全家桶+dp)

    达哥送分给我我都不要,感觉自己挺牛批. $type=0:$ 跟visit那题类似,枚举横向移动的步数直接推公式: $ans=\sum C_n^i \times C_i^{\frac{i}{2}} \t ...

随机推荐

  1. gitee+typro+picgo搭建博客图床

    gitee+typro+picgo搭建博客图床 前提环境 typro.picgo.nodejs 直接在官网下载即可 下载完成后,打开picgo 安装插件gitee-uploader 1.1-2即可显示 ...

  2. java8两个字段进行排序问题

    //这个解决问题 Comparator<Anjianxinxi> getLianriqi = Comparator.comparing(Anjianxinxi::getLianriqi). ...

  3. 未能加载文件或程序集“Microsoft.CodeDom.Providers.DotNetCompilerPlatform

    "/"应用程序中的服务器错误. 未能加载文件或程序集"Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Versio ...

  4. vue-cli的安装步骤

    1.安装Node.js 在Node.js官网 https://nodejs.org/zh-cn/下载安装包,修改安装路径到其它盘,如 G:\Program Files 2.设置 cnpm的下载路径和缓 ...

  5. P7708「Wdsr-2.7」八云蓝自动机 Ⅰ

    *X. P7708「Wdsr-2.7」八云蓝自动机 Ⅰ. 摘自 分治与根号数据结构学习笔记 第三部分 莫队 例题 X.. 一道莫队好题.私以为本题最有价值的地方在于对单点修改的转化以及对交换两个数的处 ...

  6. python19 操作mysql

    connect 模块下载 https://dev.mysql.com/downloads/connector/python/ import mysql.connector con = mysql.co ...

  7. 在R语言中使用Stringr进行字符串操作

    今天来学习下R中字符串处理操作,主要是stringr包中的字符串处理函数的用法. 先导入stringr包,library(stringr),require(stringr),或者stringr::函数 ...

  8. 用C语言的LED实验,有汇编哦!

    C语言LED实验 1.汇编激活CPU 首先要明白对于没有系统开发板(也就是裸机)来说,是没办法直接对C进行识别.所以需要一段汇编语言,来配置CPU的资源,选择CPU运行模式,初始化指针位置. 代码如下 ...

  9. 点击下拉选择触发事件【c#】

    <asp:DropDownList ID="ddlRegionList" runat="server" AutoPostBack="true&q ...

  10. 一个专业处理字符串的IDEA插件

    字符串处理想必是小伙伴们平时开发时经常碰到的一个 "难题".为什么要打上引号?因为你说他难吧,其实也不是什么特别复杂的事:你说他不难吧,弄起来还真挺麻烦的,像删除其中空行啊.切换大 ...