Block B

To test for primality, we confected a brute-force procedure. It goes like this.

  1. check if 2|n. If it does, return False.
  2. check if 3|n. If it does, return False.
  3. check if 4|n. If it does, return False.
  4. Keep going until we get to n - 1
  5. If False is never returned, return True.

def is_prime_brute(n):
    for k in range(2, n):
        if n%k == 0:
            return False
    return True
print(is_prime(61))
print(is_prime(997))
print(is_prime(1000000007))
148 4 37 factors come in pairs with ONE exception this occurs when the number is a perfect square 100 = 10*10n = 4*25 10 10 c = a*b one of a or b is <= sqrt(c) 61 2 3 4 5 6 7 DONE a <= sqrt(b) a, b >= 0 a <= b*b