Functions that answer questions
Read · 1 of 2
Check only up to √n
n is prime if nothing from 2 up to √n divides it: if n = a × b, one of them is at most √n. Loop while i * i <= n.
1def is_prime(n):2 if n < 2:3 return False4 i = 25 while i * i <= n:6 if n % i == 0:7 return False8 i += 19 return True