POJ 3518 Prime Gap (Prime question)

Source: Internet
Author: User

"Test Instructions": Enter a number, assuming that the number is a prime on the output 0, assuming that the prime is not the output from its recent two prime number difference, called Prime Gap.

"Analysis": This problem is very risky. Because I was hitting the primes table.

Since the maximum prime number is 1299709, be careful to use a long long when hitting the table. Otherwise the program should not execute. Note that this should be possible.

Accumulation!

2984K 235Ms #include <iostream>using namespace std; #define N 2000001bool isprime[n];  Long long prime[100001],nprime;  Note Long long  void Doprime ()  {      long long i,j;  // !! Note    nprime = 1;      memset (isprime,true,sizeof (IsPrime));      ISPRIME[1] = 0;      for (i = 2;i<=1299709;i++)      {          if (Isprime[i])          {              prime[nprime++] = i;              for (j = i*i;j<=1299709;j+=i)              {                  Isprime[j] = false;             }          }      }  


POJ 3518 Prime Gap (Prime question)

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.