使用篩法來解這一題,改來改去都是RE....真心不解問題點在哪
請求大神授予原因QAQ...........
程式碼如下--------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int input;
Scanner text = new Scanner (System.in);
boolean[] number = new boolean[2000000];
for(int i=0;i<2000000;i++){
number[i] = true;
}
for(int i=2;i<2000000;i++){
if(number[i]){
for(int k=i+i ; k<2000000;k=k+i){
number[k] = false;
}
}
}
while(text.hasNextInt()){
input=text.nextInt();
if(number[input]){
System.out.println("質數");
}else System.out.println("非質數");
}
}
}