import java.util.*;
public class Main{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
//testcases
int t=sc.nextInt();
//input
while(t>0){
/* String var=sc.nextLine();
String sp[]=var.split(" ")*/;
int m=sc.nextInt(); //lower
int n=sc.nextInt(); //upper
ArrayList<Integer> primes=seive(n+1);
//System.out.println(primes);
int diff=n-m+1;
boolean[] arrays=new boolean[diff];
for(int i=0;i<arrays.length;i++){arrays[i]=true;}
for(Integer prime_no:primes){
int div=(int)m/prime_no;
div*=prime_no;
while(div<=n){
if(div>=m && prime_no!=div){
arrays[div-m]=false;
}
div+=prime_no;
}
}
for(int k=0;k<arrays.length;k++){
if(arrays[k]==true)
System.out.println(k+m);
}
t--;
}
}
public static ArrayList<Integer> seive(int n){
boolean prime[]=new boolean[n];
ArrayList<Integer> list=new ArrayList<Integer>();
for(int i=0;i<n;i++){prime[i]=true;}
int p=2;
while(p*p<n){
if(prime[p]==true){
list.add(p);
for(int j=p+p;j<n;j+=p){
prime[j]=false;
}
}
p++;
}
return list;
}
}
hi all,
The above code works perfectly in ideone it but when I submit the code it gives me nzec error .
I am not able to figure out the reason behind it.
Any help will be appreciated
thank you