Find all triplet(s) (p, q, r) of prime numbers, that satisfy this equation:
p3 = p2 + q2 + r2
Justify your answer with valid reasoning.
The only one found is (3,3,3).
Analytic beginning:
If p=q=r, then p^3 = 3*p^2 for which p=3 is the only solution.
(p=0 solves but is not a prime).
p,q,r are not necessarily all equal:
p^3 = p^2 + q^2 + r^2
p^3 - p^2 = q^2 + r^2
p^2(p-1) = q^2 + r^2
and here I cannot see how to proceed. I note that (p-1) happens to be a prime only if p=3, but I am not sure that is relevant.
----------
def isprime(n):
'''check if integer n is a prime'''
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5)+1, 2):
if n % x == 0:
return False
return True
primes = [i for i in range (1000) if isprime(i)]
solutions = []
for p in primes:
for q in primes:
for r in primes:
if p**3 == p**2 + q**2 + r**2:
print([p,q,r])
if sorted([p,q,r]) not in solutions:
solutions.append(sorted([p,q,r]))
|
Posted by Larry
on 2023-05-21 10:38:40 |