Back to course home
0% completed
Vote For New Content
5. Check Prime
Problem Statement
Write a Recursive Solution to Check if a Given Number is a Prime Number or Not.
Given a positive integer, we need to determine whether it is a prime number or not. A prime number is a number greater than 1 that has no positive divisors other than 1 and the number itself.
The following table describes three example outputs for three inputs along with the description:
Input(s) | Output(s) | Explanation |
---|---|---|
Number = 7 | Is Prime = true | The number 7 is only divisible by 1 and 7, so it is a prime number. |
Number = 12 | Is Prime = false | The number 12 is divisible by 1, 2, 3, 4, 6, and 12, so it is not a prime number. |
Number = 23 | Is Prime = true | The number 23 is only divisible by 1 and 23, so it is a prime number. |
Constraints:
- 0 <= n <= 10<sup>9</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Try it yourself