I am getting NZEC runtime error for the following code for the program code: PRIME1
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!
Input
The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
Output
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
Code:
package com.alacriti.primegeneration;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args)
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t;
try{
t=Integer.parseInt(br.readLine());
String[] lineReader = new String[t];
if (t>0 && t<=10){
for (int i=0; i<t; i++)
{
lineReader[i]=br.readLine();
}
generatePrime(lineReader);
}
else return;
}
catch(NumberFormatException n)
{
return;
}
catch(InputMismatchException e)
{
return;
}
catch(RuntimeException re)
{
return;
}
catch(Exception e)
{
return;
}
}
private static void generatePrime(String[] lineReader)
{
int testCaseLength = lineReader.length;
String[] splitLine;
int reset=0;
while(reset<testCaseLength)
{
splitLine = lineReader[reset].split(" ");
if (splitLine.length==2)
{
try
{
long m=Long.parseLong(splitLine[0]);
long n=Long.parseLong(splitLine[1]);
if (n-m > 100000 || m > 1000000000 || m < 1 || n > 1000000000 || n < 1 || n < m)
{
return;
}
else
{
for(long i=m; i<=n; i++)
{
int primeCount=0;
for (int j=1; j<m/2+1;j++)
{
if (i%j==0)
{
primeCount++;
}
}
if (primeCount==1)
System.out.println(i);
}
}
}
catch(NumberFormatException n)
{
return;
}
catch(RuntimeException re)
{
return;
}
catch(Exception e)
{
return;
}
}
else{
return;
}
if (reset!=testCaseLength-1)
{
System.out.println();
}
reset++;
}
return;
}
}