2011-06-17 12:47:37Morris

[JAVA] a007. 判斷質數

/**********************************************************************************/
/*  Problem: a007 "判斷質數"                                                  */
/*  Language: JAVA                                                                */
/*  Result: AC (124ms, 5656KB) on ZeroJudge                                       */
/*  Author: new1028 at 2011-06-17 09:33:14                                        */
/**********************************************************************************/


import java.util.Scanner;
import java.lang.Math.*;
public class a007 {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()) {
            int N, a, sq;
            N = cin.nextInt();
            sq = (int)Math.sqrt(N);
            for(a = 2; a <= sq; a++)
                if(N%a == 0)    break;
            if(a != sq+1)
                System.out.println("非質數");
            else
                System.out.println("質數");
        }
    }
}