/*
Test instructions: Input has multiple sets of data, each set of data one n, if n is a prime number, output 0 otherwise output from n the last two prime number of the product, the 100,000th prime number is 1299709, all the primes within this range
Thinking: Prime Sieve method plus two points to find the lower bound
*/
#include <stdio.h>
int a[1299720],pri[100005];
int serch (int v)//binary Find Nether
{
int mid,x=0,y=100001;
while (X<y)
{
Mid= (y+x)/2;
if (PRI[MID]>=V)
Y=mid;
Else
x=mid+1;
}
printf ("pri[x]=%d\n", X);
if (PRI[X]==V)
return 0;
Else
return pri[x]-pri[x-1];
}
int main ()
{
int i,j,k=0,n;
for (i=2; i<=1299709; i++)//Sieve method
if (!a[i])
{
Pri[k++]=i;
for (j=i*2; j<=1299709; j+=i)
A[j]=1;
}
while (~SCANF ("%d", &n), N)
{
printf ("%d\n", Serch (n));
}
return 0;
}
POJ 3518 Prime Gap binary search for nether and prime sieve method