CodeForces 17A Noldbach problem
2407 단어 codeforces
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.
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.
Sample Input
Input
27 2
Output
YES
Input
45 7
Output
NO
Hint
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.
간단한 문제는 1000 이내의 각종 상황을 미리 처리하면 된다.
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int low(int x){ return x&-x; }
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
int T, n, m, f[maxn * 10], a[maxn], tot = 0;
int dp[maxn * 10];
int main()
{
for (int i = 2; i < maxn; i++)
{
if (!f[i]) a[tot++] = i;
for (int j = 0; j < tot&&a[j] * i < maxn; j++)
{
f[a[j] * i] = 1;
if (i%a[j] == 0) break;
}
}
for (int i = 1; i < tot; i++)
{
if (!f[a[i] + a[i - 1] + 1]) dp[a[i] + a[i - 1] + 1] = 1;
}
for (int i = 1; i < maxn; i++) dp[i] += dp[i - 1];
while (~scanf("%d%d", &n, &m))
{
if (dp[n] >= m) printf("YES
");
else printf("NO
");
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.