Determining the number of ways a number can be written as sum of three squares I was going through Erich Friedman's "What's Special About This Number?" and there some numbers are classified based on the number of ways we can write them as sum of squares. I want to prove the following claim by Friedman:

129 is the smallest number that can be written as the sum of 3 squares
in 4 ways.

Indeed, as given in Wikipedia,
$$11^2+2^2+2^2 = 10^2+5^2+2^2 = 8^2+8^2+1^2 = 8^2+7^2+4^2 = 129$$
So what remains to prove is that this is the smallest such number.

Is it possible to write a proof for this fact using some insights
along with brute force/cases? How can we solve this problem using only
brute-force?

Also, since I know the proof of Legendre's three-square theorem. I am also curious to know:

How can we determine the number of ways we can write a non-negative
integer which satisfies Legendre's three-square theorem as sum of
three squares?

Edit1: Related discussions on MathOverflow:

*

*Is there a simple way to compute the number of ways to write a positive integer as the sum of three squares?: Note that this is not answer of my question since $r_k(n)$ counts the number of representations of $n$ by $k$ squares, allowing zeros and distinguishing signs and order.

*Efficient computation of integer representation as sum of three squares
Edit2: Related discussions on ComputerScience.SE

*

*Listing integers as the sum of three squares $m=x^2+y^2+z^2$
Edit3: Related discussions on Mathematics.SE

*

*When is a rational number a sum of three squares?


*Why can't this number be written as a sum of three squares of rationals?


*Sum of one, two, and three squares

For the system of equations.
$$x_1^2+x_2^2+x_3^2=x_4^2+x_5^2+x_6^2=x_7^2+x_8^2+x_9^2=x_{10}^2+x_{11}^2+x_{12}^2$$
Solutions can be parameterized.
$$x_1=a(y^2+z^2+n^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_2=b(y^2+z^2+n^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_3=c(y^2+z^2+n^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_4=(ay^2-2byn+az^2-2czn-an^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_5=(bz^2-2cyz-by^2-2ayn+bn^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_6=(cy^2-2byz-cz^2-2azn+cn^2)(p^2+s^2+n^2)(k^2+t^2+n^2)$$
$$x_7=(ap^2-2bpn+as^2-2csn-an^2)(y^2+z^2+n^2)(k^2+t^2+n^2)$$
$$x_8=(bs^2-2cps-bp^2-2apn+bn^2)(y^2+z^2+n^2)(k^2+t^2+n^2)$$
$$x_9=(cp^2-2bps-cs^2-2asn+cn^2)(y^2+z^2+n^2)(k^2+t^2+n^2)$$
$$x_{10}=(ak^2-2bkn+at^2-2ctn-an^2)(y^2+z^2+n^2)(p^2+s^2+n^2)$$
$$x_{11}=(bt^2-2ckt-bk^2-2akn+bn^2)(y^2+z^2+n^2)(p^2+s^2+n^2)$$
$$x_{12}=(ck^2-2bkt-ct^2-2atn+cn^2)(y^2+z^2+n^2)(p^2+s^2+n^2)$$
It is interesting that such triples can be too much. The formula can be increased to any number. That is the same to write not only for 4 partitions, but for any number. The main thing that all the variables were not identical to each other.
