Tutte le sfide
Facile 0 risolte 0% di accettazione

Prime Number Check

Decide whether a number is prime.

A 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.

Vincoli

-1,000 ≤ n ≤ 1,000,000,000,000

Esempi

Esempio 1
Input:
n = 29

Output atteso:
expected = True
Input:
long long n = 29;

Output atteso:
bool expected = true;
Input:
long n = 29;

Output atteso:
bool expected = true;

Spiegazione

29 has no divisors other than 1 and 29.

Esempio 2
Input:
n = 21

Output atteso:
expected = False
Input:
long long n = 21;

Output atteso:
bool expected = false;
Input:
long n = 21;

Output atteso:
bool expected = false;

Spiegazione

21 = 3 × 7, so it is not prime.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.