Topic 1047: Prime Judgment
Time limit:1 seconds memory limit:
Title Description:
Given a number n, it is required to determine whether it is prime (0,1, negative numbers are non-primes).
Input:
There are several sets of test data, one for each set of n.
Output:
For each set of inputs, If the prime number is output Yes, otherwise enter no.
Sample input:
13
Sample output:
Yes
*/
/**************************************************************
problem:1047
User:watchfree
Language:java
result:accepted
TIME:80 ms
memory:15452 kb
****************************************************************
ImportJava.util.Scanner; Public classMain {Static BooleanJudgeintN) { if(n<=1)return false; if(n==2)return true; for(intI=2;I<=MATH.SQRT (n); i++){ if(n%i==0)return false; } return true; } Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in); while(Sc.hasnext ()) {intn=Sc.nextint (); if(judge (n)) System.out.println ("Yes"); ElseSystem.out.println ("No"); } sc.close (); }}
Topic 1047: Prime Judgment