ExamAdda Logo

Check for Prime Number

Easy

Given a positive integer n, determine whether it is a prime number.

A prime number is a natural number greater than 1 that has exactly two distinct positive divisors: 1 and itself.

Return true if the given number is prime; otherwise, return false.

Example 1

Input

7

Output

true

Explanation

7 has exactly two positive divisors: 1 and 7.

Therefore, it is a prime number.

Example 2

Input

12

Output

false

Explanation

12 has more than two positive divisors: 1, 2, 3, 4, 6 and 12.

Therefore, it is not a prime number.

Constraints

1 ≤ n ≤ 10^9

Hints:

Hint 1

A number greater than 1 is prime if it has no divisors other than 1 and itself.

Hint 2

Instead of checking all numbers from 2 to n-1, it is sufficient to check divisors only up to √n.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Jul 21, 2026

Last updated

Aug 6, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output