A prime number is a positive integer that is divisible by exactly 2 integers, 1 and the number itself.
You are given a number 'n'.
Find out whether 'n' is prime or not.
Input: 'n' = 5
Output: YES
Explanation: 5 is only divisible by 1 and 5. 2, 3 and 4 do not divide 5.
The first line of a test case contains a single integer 'n'.
Print “YES” if the number 'n' is prime. Print “NO” otherwise.
You do not need to print anything; it has already been taken care of. Just implement the given function and return the boolean value true/false depending on whether 'n' is prime or not.
5
YES
5 is only divisible by 1 and 5. 2, 3 and 4 do not divide 5.
6
NO
6 is divisible by 1, 2, 3, and 6. Therefore it is not a prime number.
Numbers having more than two factors are known as composite numbers.
1
NO
1 is divisible only by 1, having only one factor. Therefore it is not a prime number.
1 is neither a prime nor a composite number.
The expected time complexity is O(sqrt('n')).
1 <= 'n' <= 10 ^ 9
Time limit: 1 second