Numbers which are not the sum of distinct squares: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl) |
(Added XPL0 example.) |
||
Line 608: | Line 608: | ||
Found 31 total in 24 ms. |
Found 31 total in 24 ms. |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
This generates all combinations of sums of N squared up to a Limit. For |
|||
a Limit = 1000 = $3E8 = %11_1110_1000 this sums 100+81+64+49+36+16. A Limit of one million |
|||
shows that there is a huge gap following 128 of values that cannot be |
|||
generated by any combination of sums of squares. The mathematical |
|||
argument why none exist beyond 128 is provided by the Julia example. |
|||
<syntaxhighlight lang "XPL0">func SumSq(B); \Return sum of squares specified by bits in B |
|||
int B, N, Sq, Sum; |
|||
[N:= 1; Sum:= 0; |
|||
while B do |
|||
[if B & 1 then |
|||
[Sq:= N*N; |
|||
Sum:= Sum + Sq; |
|||
]; |
|||
B:= B>>1; |
|||
N:= N+1; |
|||
]; |
|||
return Sum; |
|||
]; |
|||
def Limit = 1_000_000; |
|||
char Flags(Limit); |
|||
int I; |
|||
[for I:= 0 to Limit-1 do |
|||
Flags(I):= true; |
|||
for I:= 0 to Limit-1 do |
|||
if I < Limit then |
|||
Flags(SumSq(I)):= false; |
|||
for I:= 0 to sqrt(Limit)-1 do |
|||
if Flags(I) then |
|||
[IntOut(0, I); ChOut(0, ^ )]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2 3 6 7 8 11 12 15 18 19 22 23 24 27 28 31 32 33 43 44 47 48 60 67 72 76 92 96 108 112 128 </pre> |