Answer to Question #255745 in Python for Emre

Question #255745

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.


1
Expert's answer
2021-10-28T01:22:58-0400
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=", ")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS