Find positive integers X, Y and N satifying the Pell equation: X² - N*Y² = 1 such that X, Y and N together contain all of the decimal digits 0 to 9 exactly once.
Note: The solution is unique when X,Y,N > 1.
The second solution is when Y=1. So indeed the solution is unique when X,Y,N > 1
(X,Y,N) = (458, 1, 209763)
458^2 - 209763*1^2 = 1
(X,Y,N) = (9801, 364, 725)
9801^2 - 725*364^2 = 1
I did some analysis to see how many digits each of X, Y, and N can have and looped through X and Y values of the appropriate ranges.
Also made lookup dictionaries for squares.
--------------
x_2 = [i**2 for i in range(316, 31624)]
y_2 = [i**2 for i in range(1,10000)]
x_dict = {xsqrd: int(round(xsqrd**.5)) for xsqrd in x_2}
y_dict = {ysqrd: int(round(ysqrd**.5)) for ysqrd in y_2}
solutions = []
for ysquared in y_2:
for xsquared in x_2:
calc = (xsquared - 1) / ysquared
if calc%1 == 0:
n = int(calc)
x = x_dict[xsquared]
y = y_dict[ysquared]
digits = str(x)+str(y)+str(n)
if len(digits) != 10:
continue
if len(set(digits)) == 10:
print(x,y,n, x**2 - n*y**2)
solutions.append([x,y,n])
print()
for s in solutions:
print(s, s[0]**2 - s[2]*s[1]**2)
OUTPUT:
[458, 1, 209763] 1
[9801, 364, 725] 1
Edited on April 6, 2024, 11:13 am
|
Posted by Larry
on 2024-04-06 11:10:50 |