Problem 8
Prime Number Check
Easy · 10 pts · Math
Problem
You are given an integer N. Decide whether N is a prime number: a whole number greater than 1 whose only positive divisors are 1 and itself. The numbers 0 and 1 are not prime. To check N efficiently, you only need to test divisors d with d × d <= N, because if N has a divisor larger than its square root, it also has a matching divisor smaller than it. That is at most about 31,623 checks for N up to one billion.
Input
A single integer N.
Output
Print true if N is prime; otherwise print false.
Constraints
0 <= N <= 1000000000
Example input
7
Example output
true
Explanation
For N = 7, no number from 2 up to the square root of 7 (only 2 needs checking) divides 7, so its only divisors are 1 and 7. It is prime, so the answer is true.