Max Alekseyev on Mon, 17 Nov 2025 15:29:13 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: N = a^2 + b^2 + c^2 question


There is an analytical formula for this count - see 
https://en.wikipedia.org/wiki/Sum_of_squares_function#k_=_3

Regards,
Max


On Mon, Nov 17, 2025 at 4:59 AM Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Sun, Nov 16, 2025 at 05:32:52PM -0800, American Citizen wrote:
> In trying to obtain a fast but exhaustive algorithm for finding 3 squares
> which sum to a given number n, I found that using n = 416666, I obtained 339
> unique representations of [a,b,c] such that a^2+b^2+c^2 = n.
>
> Can anyone verify that this count is correct for n?

Yes this is correct. Using the most straightword way:
? my(c=0);forvec(v=[[0,1000],[0,1000],[0,1000]],if(norml2(v)==416666,c++;print(c,":",v)),1);print(c);
%1 = 339

Cheers,
Bill.