OFFSET
2,1
COMMENTS
We impose y < n to exclude the trivial solution x = 1, y = n, a(n) = -1.
Then there is no admissible pair (x, y) for n = 1, whence a(1) is undefined.
FORMULA
a(n) = 0 for Hypotenuse numbers, n in A009003.
EXAMPLE
For n = 2, the largest possible x = y = 1 give the minimal n^2 - x^2 - y^2 = 4 - 2 * 1^2 = 2 = a(2).
Similarly, for n = 3 and n = 4, the largest possible x = y = n - 1 give the minimal a(n) = n^2 - 2*(n-1)^2, a(3) = 9 - 2*4 = 1 and a(4) = 16 - 2*9 = -2.
For n = 5 which is a hypotenuse number (<=> has a prime factor of the form 4k+1), we have a(5) = 5^2 - 3^2 - 4^2 = 0.
PROG
(PARI) A369862(n, p=2) = { my(np=n^p, m=np); for(y=max(sqrtnint(np\2, p), 1), n-1, my(x = sqrtnint(np - y^p, p), dy = np-y^p, d = if(dy-x^p > (x+1)^p-dy && x < n-1, dy-(x+1)^p, dy-x^p)); abs(d) < abs(m) && !(m=d) && break); m} \\ Not optimized: one could immediately return 0 when a solution of x^2 + y^2 = n^2 is known to exist, and similarly with n^2 +- k for small k.
CROSSREFS
KEYWORD
sign
AUTHOR
M. F. Hasler, Feb 03 2024
STATUS
approved