801. Check if a Number is Prime or Not

Given an integer num, return true if it is prime otherwise false.

A prime number is a number that is divisible only by 1 and itself.

Example 1:

Input : num = 5

Output : true

Explanation : The factors of 5 are 1 and 5 only.

So it satisfies the prime number condition.

Example 2:

Input : num = 15

Output : false

Explanation : The factors of 15 are 1, 3, 5, 15 only.

As the number has factors other than 1 and itself, So it is not a prime number.

Now Your Turn!

Pick the correct output for the given input

Input : num = 41

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= num <= 104
0
class Solution{
public:
bool checkPrime(int num){
//your code goes here
}
};
Test Case

Input:

Nums