Check for Prime
EasyP2Coding
Given an integer n, return true if it is a prime number and false otherwise.
A prime is an integer greater than 1 whose only positive divisors are 1 and itself.
Example 1
- Input
- n = 7
- Output
- true
Example 2
- Input
- n = 1
- Output
- false
Example 3
- Input
- n = 2
- Output
- true
Constraints
- 0 <= n <= 10^9
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.