a, b, and x are positive integers such that
sqrt(a) + sqrt(b) = sqrt(x)
How many possible values of x less than or equal to 1000 are there?
I found 392 values of x and 961 values of {a,b,x} where a <= b.
In the line below marked in boldface, I initially just had
if x > 1000 but this introduced a rounding error where I missed 2 values of {a,b,x} although the number of x values was unchanged.
ans = []
eps = .0000001
for a in range(1, 1000):
sqrt_a = a ** .5
for b in range(a, 1000):
sqrt_b = b ** .5
x = (sqrt_a + sqrt_b)**2
if x > 1000 + eps:
continue
frac = x%1
if frac < eps:
x = x//1
ans.append([a,b,int(x)])
if (1-frac) < eps:
x = x//1 + 1
ans.append([a,b,int(x)])
xvalues = []
for a in ans:
if a[2] not in xvalues:
xvalues.append(a[2])
print (len(ans))
print (len(xvalues))
|
Posted by Larry
on 2023-03-25 09:25:31 |