Checking positive integers up to 10,000 finds three results, but only one result with x and y both being composite.
The requested product is 21021.
program output:
67 53 x is prime; y is prime
147 143 neither x nor y is prime
the requested product is 21021
1011 1013 x is composite; y is prime
----------------------------
big = 10001
for x in range(1,big):
for y in range(1,big):
if x**2 - y**2 == 2026 - 2*(x + 2*y):
bothcomposite = True
if isprime(x):
msg1 = 'x is prime;'
bothcomposite = False
else:
msg1 = 'x is composite;'
if isprime(y):
msg2 = 'y is prime'
bothcomposite = False
else:
msg2 = 'y is composite'
if bothcomposite:
print(x,y, 'neither x nor y is prime')
print(' the requested product is', x*y)
else:
print(x,y,msg1,msg2)
|
Posted by Larry
on 2024-02-29 11:07:17 |