"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)