zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #17 A.素数相关

    A. 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.

    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.

    Examples
    input
    27 2
    output
    YES
    input
    45 7
    output
    NO
    Note

    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.

    题意:问2到n间有多少个素数为两个相邻素数相加加一;

    思路:暴力就好了

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    #define true ture
    #define false flase
    using namespace std;
    #define ll __int64
    #define inf 0xfffffff
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF )  return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    int p[100010],flag[100010];
    int prime(int n)
    {
        if(n<=1)
        return 0;
        if(n==2)
        return 1;
        if(n%2==0)
        return 0;
        int k, upperBound=n/2;
        for(k=3; k<=upperBound; k+=2)
        {
            upperBound=n/k;
            if(n%k==0)
                return 0;
        }
        return 1;
    }
    int main()
    {
        int ji=0;
        for(int i=2;i<=1000;i++)
        {
            if(prime(i))
            p[ji++]=i;
        }
        for(int i=1;i<ji;i++)
        {
            int gg=p[i]+p[i-1]+1;
            if(prime(gg))
            flag[gg]=1;
        }
        int x,y;
        int ans=0;
        scanf("%d%d",&x,&y);
        for(int i=2;i<=x;i++)
        if(flag[i])
        ans++;
        if(ans>=y)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    excel 批量修改sql
    js select 改变当前选中option
    servlet 显示服务器上的图片
    @Security权限验证拦截参数
    签字 变成 图片 纯js+html实现
    web 的项目 搭乘war包,运行时候却找不到jar包
    jquery监听扫码枪获得值
    妹子的js 万一哪一天资源找不到了 记录下来
    react系列---【redux安装、创建仓库】
    react系列---【redux进阶】
  • 原文地址:https://www.cnblogs.com/jhz033/p/5459248.html
Copyright © 2011-2022 走看看