Topic 1047: Prime Judgment

Source: Internet
Author: User

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&LT;=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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.