問題
翻訳を表示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.
制約
-1,000 ≤ n ≤ 1,000,000,000,000
例
例 1
入力:
n = 29
期待される出力:
expected = True
入力:
long long n = 29;
期待される出力:
bool expected = true;
入力:
long n = 29;
期待される出力:
bool expected = true;
解説
29 has no divisors other than 1 and 29.
例 2
入力:
n = 21
期待される出力:
expected = False
入力:
long long n = 21;
期待される出力:
bool expected = false;
入力:
long n = 21;
期待される出力:
bool expected = false;
解説
21 = 3 × 7, so it is not prime.
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。