Is Prime

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C++, Java, Python

A number is prime if the only numbers by which it can be evenly divided are itself and 1. Given a number, determine if it is prime.

Input

The input will be a positive integer no greater then 1 million.

Output

If the number is prime, print YES, otherwise print NO.

Sample Input

2

Sample Output

YES

Comments


  • -1
    WesleyG  commented on Dec. 11, 2023, 2:12 p.m.

    import java.io.; import java.util.; import java.util.Scanner; public class Main { Public static void main(String[]args){ Scanner input = new Scanner(System.in); int num = input.nextInt(); input.close(); boolean flag = false;

    for (int i =2; i ,= num / 2; ++i){ if (num%i == 0){ flag = true; break; } } if (!flag){ System.out.println("Yes") } else { System.out.println("No"); } } }