Menu
CoddyTech

Check Prime Number

A prime number is a whole number greater than 1 whose only divisors are 1 and itself. You get a positive integer n. Return true if n is prime and false otherwise. The number 1 is not prime.

Function

isPrime(n: integer) → boolean
ninteger
the positive integer to test
Returnsboolean
true if n is prime, false otherwise

Constraints

  • 1 ≤ n ≤ 231 - 1

Examples

Input
n = 29
Output
true
Explanation
None of 2, 3, 4 or 5 divides 29, and 6 × 6 = 36 is already past 29, so no divisor is left to find. 29 is prime.

lock icon+15 hidden tests on Submit

challenge icon

Follow-up

Every prime above 3 has the form 6k-1 or 6k+1. Can you use that to test only a third of the candidate divisors?

Reset code
def isPrime(n):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

n = 29

Expected

true