<filename>files/code/amicable.py
import numpy as np

def is_prime(n):
    up = int(np.sqrt(n))
    for i in range(2, up+1):
        if n % i == 0:
            return False
    return True

n = 3
while True:
    p = 3 * 2 ** (n-1) - 1
    if not is_prime(p):
        n += 1
        continue
    q = 2 * p + 1
    if not is_prime(q):
        n += 1
        continue
    r = p * q + p + q
    if not is_prime(r):
        n += 1
        continue
    c = 2 ** n
    print('a=', c * p * q)
    print('b=', c * r)
    break
<filename>files/code/amicable.py
import numpy as np

def is_prime(n):
    up = int(np.sqrt(n))
    for i in range(2, up+1):
        if n % i == 0:
            return False
    return True

n = 3
while True:
    p = 3 * 2 ** (n-1) - 1
    if not is_prime(p):
        n += 1
        continue
    q = 2 * p + 1
    if not is_prime(q):
        n += 1
        continue
    r = p * q + p + q
    if not is_prime(r):
        n += 1
        continue
    c = 2 ** n
    print('a=', c * p * q)
    print('b=', c * r)
    break