#7794: (Java) WA為什麼~~~ 幫幫我


smllai (Jane)


import java.util.Scanner;

public class a007 {
    public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();

for (int i = 2;i<=Math.sqrt(a) ;i++ )
{
while(a%i==0)
{
System.out.println("非質數");
System.exit(0);
}

}
System.out.println("質數");

}
}

沒有逾時,在本機跑也都沒問題 麻煩大家幫幫忙~~
謝謝 
#7856: Re:(Java) WA為什麼~~~ 幫幫我


kaka80409 (Budont)




a=9 -> 非質數

但sqrt(9) == 3 -> 質數

所以WA

#7857: Re:(Java) WA為什麼~~~ 幫幫我


kaka80409 (Budont)




Sorry 我看錯了