Codeforces Beta Round #17 A - Noldbach problem 暴力
2016-12-13 14:36
2835 查看
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 17A Noldbach problem(数学)
- D - Noldbach problem CodeForces - 17A
- CodeForces-17A-Noldbach problem
- Noldbach problem
- 【水遍历\打表】#17 A. Noldbach problem
- cf17A Noldbach problem (素数打表)
- codeforces 17A Noldbach problem
- CodeForces 17 A.Noldbach problem(水~)
- 17A Noldbach problem
- A. Noldbach problem
- 17A. Noldbach problem
- Math Problem HDU - 5105 暴力求解/公式
- 【codeforces 749A】Bachgold Problem
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
- Problem 14 Longest Collatz sequence(暴力)
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
- HDOJ 题目A very hard Aoshu problem(暴力,DFS)
- HDU 4403 A very hard Aoshu problem (DFS暴力)
- UVa Problem 10132 File Fragmentation (文件还原) 排列组合+暴力
- HDU 5328(Problem Killer-暴力)