Prime Number
Practice this coding question on Coding Gurukul.
Problem statement
A workshop wants to arrange n identical tiles into equal rows. A prime tile count permits only the trivial layouts with one row or one tile per row. Your task Determine whether the integer n is prime. Important details A prime is an integer greater than one with exactly two positive divisors: one and itself. Thus zero and one are not prime, while two is prime. A composite number has a divisor no greater than its square root, so check potential divisors only as far as necessary. Perfect squares must be handled correctly by including the square-root boundary in the check. Worked example For n = 29, no integer from 2 through 5 divides it, so print true. For 49, the divisor 7 proves the answer is false.
Input format
One integer n.
Output format
Print true for a prime, otherwise false.
Constraints
0 <= n <= 1000000000.
Sample input
29
Sample output
true
Sign in to run or submit a solution in C++, Java or Python.