login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

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

%I #16 Feb 04 2024 18:36:20

%S 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,

%T 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,

%U 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

%N 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.

%C We impose y < n to exclude the trivial solution x = 1, y = n, a(n) = -1.

%C Then there is no admissible pair (x, y) for n = 1, whence a(1) is undefined.

%F a(n) = 0 for Hypotenuse numbers, n in A009003.

%e 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).

%e 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.

%e 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.

%o (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.

%Y Cf. A135998 (equivalent for 3rd powers), A308834 (4th powers), A369855 (5th powers).

%Y Cf. A009003.

%K sign

%O 2,1

%A _M. F. Hasler_, Feb 03 2024