I am trying to solve Spoj prime generator using Sieve Of Eratosthenes But am getting NZEC error. Can anybody help me . Some users have said using sieve already would help me .
import java.util.*;
public class Main
{
public static void main (String args[])
{
Scanner sc =new Scanner(System.in);
int n =sc.nextInt();
int g,h;
int isPrime[]=new int[1000000000];
for (int j=3;j<1000000000;j++)
{
isPrime[0]=0;
isPrime[1]=0;
isPrime[2]=1;
if(j%2==0)
isPrime[j]=0;
else
isPrime[j]=1;
}
for(int k=3;k<=Math.sqrt(1000000000);k=k+2)
{
if(isPrime[k]==1)
for (int l=k*k;l<1000000000;l=l+k)
{
isPrime[l]=0;
}
}
for (int i=0;i<n;i++)
{
g =sc.nextInt();
h =sc.nextInt();
for (int m=g; m<=h;m++)
{
if(isPrime[m]==1)
System.out.println(m);
}
System.out.println();
}
System.exit(0);
}
}`