login
A369862
a(n) is the smallest error in trying to solve n^2 = x^2 + y^2: given n >= 2, find positive integers x <= y < n such that |n^2 - x^2 - y^2| is minimal and let a(n) = n^2 - x^2 - y^2. In case of a tie, choose the value with the smallest y.
1
2, 1, -2, 0, 2, -1, -1, 1, 0, -4, -1, 0, 2, 0, -4, 0, -1, 1, 0, -1, -1, -1, -2, 0, 0, -1, -1, 0, 0, -1, -1, 1, 0, 0, -4, 0, -1, 0, 0, 0, -1, -1, -1, 0, -1, -1, -1, -3, 0, 0, 0, 0, -4, 0, 3, -1, 0, -4, 0, 0, -1, -1, -1, 0, 4, -1, 0, -4, 0, -3, -1, 0, 0, 0, -1, -1, 0, -4, 0, 1, 0, -1, -2, 0, -1, 0, -1, 0, 0, 0, -1, -1, 3, 0, -1, 0, -1, 1
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
Cf. A135998 (equivalent for 3rd powers), A308834 (4th powers), A369855 (5th powers).
Cf. A009003.
Sequence in context: A079483 A262115 A071460 * A218867 A295664 A250213
KEYWORD
sign
AUTHOR
M. F. Hasler, Feb 03 2024
STATUS
approved