Problem 171764 · easy · Phase 01 Prerequisites & Setup

Prime or Not?

loops · modulo · early return · math

A prime number is an integer greater than 1 whose only positive divisors are 1 and itself. Write is_prime(n) that returns True if n is prime and False otherwise. Numbers less than 2 are never prime.

Examples

Input:  n = 7
Output: True

Input:  n = 1
Output: False

Constraints

  • -10**9 <= n <= 10**9
  • Tip: you only need to test divisors d while d * d <= n.

Goals

  • Test divisibility inside a loop
  • Return early as soon as the answer is known
Starting Python…