login
Smallest k such that n^2 = a_1^2 + ... + a_k^2 and all a_i are positive integers less than n.
6

%I #23 Feb 12 2024 07:26:57

%S 4,3,4,2,3,3,4,3,2,3,3,2,3,2,4,2,3,3,2,3,3,3,3,2,2,3,3,2,2,3,4,3,2,2,

%T 3,2,3,2,2,2,3,3,3,2,3,3,3,3,2,2,2,2,3,2,3,3,2,3,2,2,3,3,4,2,3,3,2,3,

%U 2,3,3,2,2,2,3,3,2,3,2,3,2,3,3,2,3,2,3,2,2,2,3,3,3,2,3,2,3,3,2,2,2,3,2,2,2

%N Smallest k such that n^2 = a_1^2 + ... + a_k^2 and all a_i are positive integers less than n.

%C Related to hypotenuse numbers: A161882(A009003(n))=2 for all n.

%C Jacobi's four-square theorem can be used to show that a(n) <= 4. - _Charles R Greathouse IV_, Jul 31 2011

%H Alois P. Heinz, <a href="/A161882/b161882.txt">Table of n, a(n) for n = 2..700</a>

%H Jean-Charles Meyrignac, <a href="http://euler.free.fr/">Computing minimal equal sums of like powers</a>.

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/DiophantineEquation2ndPowers.html">Diophantine Equation 2nd Powers</a>.

%F a(n)=2 iff n is in A009003 (hypotenuse numbers), a(n)=4 iff n is in A000079 (powers of 2), otherwise a(n)=3. - _M. F. Hasler_, Dec 17 2014

%e 2^2 = 1^2 + 1^2 + 1^2 + 1^2, so a(2)=4.

%e 3^2 = 2^2 + 2^2 + 1^2, so a(3)=3.

%t f[n_, k_] := Select[PowersRepresentations[n^2, k, 2], AllTrue[#, 0<#<n&]&];

%t a[n_] := For[k = 2, True, k++, If[f[n, k] != {}, Return[k]]];

%t a /@ Range[2, 200] (* _Jean-François Alcover_, Oct 03 2020 *)

%o (PARI) A161882(n)={vecmin(factor(n)[,1]%4)==1 && return(2); if(n==1<<valuation(n,2),4,3)} \\ _M. F. Hasler_, Dec 17 2014

%Y Cf. A161883, A161884, A161885.

%K nonn

%O 2,1

%A _Dmitry Kamenetsky_, Jun 21 2009

%E More terms from _Alois P. Heinz_, Dec 04 2014