G.py - ISPRIM
As you already known, a prime number is a number greater than 1 that has only two distinct positive divisors: 1 and itself.
Your task is to write a function is_prime(n)
that checks whether the given integer n
is a prime number.
Hint: Count the factors of the number from 1 to itself. If the number has exactly two factors (1 and itself), then the number is prime, return
True
. Otherwise, return
False
.
Input: An integer n
.
Output: Return True
if n
is a prime number, otherwise return False
.
Example 1:
Input: n = 7
Return: True
Explanation: 7 is a prime number because it has only two divisors: 1 and 7.
Example 2:
Input: n = 10
Return: False
Explanation: 10 is not a prime number because it has more than two divisors: 1, 2, 5, and 10.
Example 3:
Input: n = 11
Return: True
Explanation: 11 is a prime number because it only has two divisors: 1 and 11.
Example 4:
Input: n = 113
Return: True
Explanation: 113 is a prime number because it has only two divisors: 1 and 113.