Problème
Afficher la traductionA prime number is greater than 1 and divisible only by 1 and itself. Checking divisors up to the square root of n is enough.
Implement is_prime(n).
Input
n: The number to test.
Output
Return true if n is prime, otherwise false.
Contraintes
-1,000 ≤ n ≤ 1,000,000,000,000
Exemples
Exemple 1
Entrée :
n = 29
Sortie attendue :
expected = True
Entrée :
long long n = 29;
Sortie attendue :
bool expected = true;
Entrée :
long n = 29;
Sortie attendue :
bool expected = true;
Explication
29 has no divisors other than 1 and 29.
Exemple 2
Entrée :
n = 21
Sortie attendue :
expected = False
Entrée :
long long n = 21;
Sortie attendue :
bool expected = false;
Entrée :
long n = 21;
Sortie attendue :
bool expected = false;
Explication
21 = 3 × 7, so it is not prime.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.