PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000018. Số nguyên tố (Primality Test)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số nguyên tố (Primality Test)
Primality Test
Source: LQDOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer is called prime if it has exactly two distinct positive divisors: and itself. Therefore, is not prime, and is the smallest prime number.
Given a positive integer , determine whether it is prime. The result must be exact even for large values of .
Input
The only line contains a positive integer .
Output
Print exactly YES if is prime; otherwise print NO. Letter case is significant.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
9
Output
NO
Explanation: For , the factorization shows that is another divisor besides and . Thus, print NO.
Example 2
Input
97
Output
YES
Explanation: For , the primes not exceeding are . None divides , so it is prime and the output is YES.