Determine the smallest positive integer that can be expressed as the sum of three nonzero squares in five different ways.
v=zeros(1,200^2);
% find sums, keeping count
for tot=1:100
for a=1:tot/3
a2=a^2;
for b=a:(tot-a)/2
c=tot-a-b;
n=a2+b^2+c^2;
v(n)=v(n)+1;
end
end
end
% find count >= 5
for i=1:length(v)
if v(i)>=5
disp([i v(i)])
break
end
end
% report stats on the one found
for tot=1:100
for a=1:tot/3
a2=a^2;
for b=a:(tot-a)/2
c=tot-a-b;
n=a2+b^2+c^2;
if n==i
disp([a b c a^2 b^2 c^2])
end
end
end
end
finds that 194 is the first such sum:
194 5
a b c a^2 b^2 c^2
1 7 12 1 49 144
3 4 13 9 16 169
3 8 11 9 64 121
5 5 12 25 25 144
7 8 9 49 64 81
|
Posted by Charlie
on 2024-07-27 08:12:31 |