A simple numerical experiment shall confirm the answer given by zhoraster: the latter is only deviant from mine by a factor $2$. We define an initial segment of the naturals with length $N$ and count all sums of two squares in that segment. The accompanying program is in Pascal:
program kwadraat;
procedure test(N : integer);
type
data = record
b : boolean; i,j : integer;
end;
var
i,j,k,t : integer;
rij : array of data;
begin
t := 0;
SetLength(rij,N);
for k := 0 to N-1 do
begin
rij[k].b := false;
end;
i := 0;
while true do
begin
if sqr(i) > N-1 then Break;
j := i;
while true do
begin
k := sqr(i)+sqr(j);
if k > N-1 then Break;
{ Writeln(k,' = ',i,'^2 + ',j,'^2'); }
rij[k].i := i; rij[k].j := j;
rij[k].b := true;
j := j + 1;
t := t + 1;
end;
i := i + 1;
end;
if N < 100 then
for k := 0 to N-1 do
begin
if rij[k].b then
Writeln(k,' = ',rij[k].i,'^2 + ',rij[k].j,'^2');
end;
Writeln(t/N,' ->',Pi/8);
end;
begin
test(10);
test(1000);
test(100000);
test(10000000);
end.
Output (details for $N=10$ only):
0 = 0^2 + 0^2
1 = 0^2 + 1^2
2 = 1^2 + 1^2
4 = 0^2 + 2^2
5 = 1^2 + 2^2
8 = 2^2 + 2^2
9 = 0^2 + 3^2
7.00000000000000E-0001 -> 3.92699081698724E-0001
4.19000000000000E-0001 -> 3.92699081698724E-0001
3.95420000000000E-0001 -> 3.92699081698724E-0001
3.92969900000000E-0001 -> 3.92699081698724E-0001
Note that the results converge to $\;\pi/8$ , quite in agreement with the argument given by zhoraster, provided though that $i^2 + j^2$ and $j^2 + i^2$ give a double count of $\,\pi/4\,$ which must be halved.
EDIT. Question & Answer is related to :
Double Think about Numerosity .
BONUS. In one of the comments with the answer by zhoraster, VividD has been asking for a variant of the original question for the sum of three/four squares. Minor modification of the above program gives the following output for the three squares case. It is seen that some numbers can be written as a sum of three squares in more than one way. Therefore two cases shall be distinguished: with or without these duplicates. Details again for $N=10$ :
0 = 0^2 + 0^2 + 0^2
1 = 0^2 + 0^2 + 1^2
4 = 0^2 + 0^2 + 2^2
9 = 0^2 + 0^2 + 3^2
2 = 0^2 + 1^2 + 1^2
5 = 0^2 + 1^2 + 2^2
8 = 0^2 + 2^2 + 2^2
3 = 1^2 + 1^2 + 1^2
6 = 1^2 + 1^2 + 2^2
9 = 1^2 + 2^2 + 2^2
with duplicates = 10/10
without duplicates = 9/10
with duplicates = 3254/1000
without duplicates = 835/1000
with duplicates = 2807201/100000
without duplicates = 83336/100000
with duplicates = 87741031/1000000
without duplicates = 833336/1000000
If the duplicates are counted, then the results are seen to diverge $\to \infty$ .
It is conjectured that, without the duplicates, the results converge to : $5/6$ (Michael Lugo).
Any takers to
prove the latter statement?