Find all possible pairs (x, y) of prime numbers, with x less than or equal to y, and each of x and y being less than 2023, such that:
• y divides x2 + 8 and,
• x divides y2 + 8
Provide valid reasoning as to why there are no further solutions.
*** Extra credit for an analytical solution.
Note: This puzzle is adapted from a problem appearing in the Zhautykov Olympiad.
Three solutions found given the constraints:
(2,2)
(3,17)
(89,881)
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(2024) if isprime(i)]
for x in primes:
for y in primes:
if y < x:
continue
if (x**2+8)%y == 0 and (y**2+8)%x == 0:
print('({},{})'.format(x,y))
|
Posted by Larry
on 2023-03-18 08:23:01 |