Sdut 3305 Prime number in prime (prime sieve)

Source: Internet
Author: User

Prime numbers in prime numbers Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title Description If a prime number, it is also prime in prime numbers, which is called prime numbers in prime numbers. For example 3 is a 2nd prime number, so 3 is prime number, although 7 is a prime number, but 7 in 4th place, so 7 is not prime numbers in the prime to give you a count of N, to find out the >=n of a minimum prime number of prime numbers in the input input one n (0<=n <= 10^6)

Prime number in the smallest prime number of the output >=n

Sample input
234
Sample output
335
Hint Source
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath>using namespace Std;int b[1500001];int n;int vis[5000010];int a[1500001];int pan ()                     //prime sieve {    int m=sqrt ( 2000000+0.5);    memset (vis,0,sizeof (Vis));    for (int i=2;i<=m;i++)        if (!vis[i]) for    (int j=i*i;j<=2000000;j+=i)             vis[j]=1;} int P () {    int num=85714;<span id= "Transmark" ></span> for    (int i=1100003;i>=2;i--)    {        if (vis[i]==0)        {            b[num]=i;            if (vis[num]==0)            {              a[i]=num;            }            else                a[i]=a[i+1];            num--;        }        else            {a[i]=a[i+1];}}}    int main () {    pan ();    P ();   while (~SCANF ("%d", &n))   {       if (n==0| | n==1)        printf ("2\n");      cout<<a[n];      else      printf ("%d\n", B[a[n]]);   }    

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sdut 3305 Prime number in prime (prime sieve)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.