while running my code i am getting error
signal 15 and time limit exceeded on wall time.
Getting signal 15 as error
Please post your code here.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
//int []p=new int[1000000];
int [] p=new int[1000000];
int i;
for(i=0;i<1000000;i++)
p[i]=0;
prime_sieve(p);
int[] sum = new int[1000000];
int next=0;
int prev=0;
while(next<999999)
{
sum[i]=p[next]+p[prev];
prev=next;
next=next+1;
i++;
}
i=1;
while(i<=n)
{
int a=scn.nextInt();
int b=scn.nextInt();
int count= sum[b]-sum[a-1];
System.out.println(count);
i++;
}
}
public static void prime_sieve(int []p)
{
int i=3;
int k,j;
for(i=3;i<1000000;i=i+2)
p[i]=1;
for(i=3;i<1000000;i=i+2)
{
if(p[i]==1)
{
for(k=2*i;k<1000000;k=k+i)
p[k]=0;
}
}
p[2]=1;
p[1]=p[0]=0;
//return p;
}
}
It should throw runtime error because before executing the while loop with the next and prev stuff, you should’ve set the value of I back to 1 but since you didn’t it should go out of bounds