Write a Python function that finds and prints all the prime numbers, pn, that satisfy the following equation: pn=2k+3L
for some non-negative integers k,L, such that k≤16, L≤16.
from math import sqrt
def is_prime(num):
if (num < 2 or num % 2 == 0):
return (num == 2)
divisor = 3
while (divisor <= sqrt ( num )):
if (num % divisor == 0) :
return False
else :
divisor += 2
return True
res = set()
for k in range(17):
for l in range(17):
if is_prime(2**k + 3**l):
res.add(2**k + 3**l)
print(*sorted(res),sep=", ")
Comments
Leave a comment