packagemath;importjava.util.Scanner;publicclassSeieveOfEratosthenes{publicstaticvoidgetPrimebyRange(inta,intb){int[]primes=newint[b+1];// 소수 저장intpn=0;// 소수의 개수boolean[]check=newboolean[b+1];check[0]=check[1]=true;for(inti=2;i*i<=b;i++){if(check[i]==false){//primes[pn++] = i;for(intj=i+i;j<=b;j+=i){check[j]=true;}}}for(inti=a;i<=b;i++){if(check[i]==false){System.out.println(i);}}}publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);inta=sc.nextInt();intb=sc.nextInt();getPrimebyRange(a,b);}}
Comments