Numbers which are not the sum of distinct squares: Difference between revisions
Content added Content deleted
(Added solution for Modula-2) |
(Added Quite BASIC and Gambas) |
||
Line 116: | Line 116: | ||
found 31 total in 9.9693 ms |
found 31 total in 9.9693 ms |
||
stopped checking after finding 128 sequential non-gaps after the final gap of 128</pre> |
stopped checking after finding 128 sequential non-gaps after the final gap of 128</pre> |
||
=={{header|BASIC}}== |
|||
==={{header|FreeBASIC}}=== |
|||
{{trans|XPL0}} |
|||
<syntaxhighlight lang="vb">Function SumSq(num As Integer) As Integer 'Return sum of squares specified by bits in num |
|||
Dim As Integer n = 1, suma = 0, Sq |
|||
While num |
|||
If num And 1 Then |
|||
Sq = n*n |
|||
suma += Sq |
|||
End If |
|||
num Shr= 1 |
|||
n += 1 |
|||
Wend |
|||
Return suma |
|||
End Function |
|||
Dim As Integer limite = 1e6, cant = 0, i |
|||
Dim As Boolean flags(limite) |
|||
For i = 0 To limite-1 |
|||
flags(i) = True |
|||
Next |
|||
For i = 0 To limite-1 |
|||
If i < limite Then flags(SumSq(i)) = False |
|||
Next |
|||
For i = 0 To Sqr(limite)-1 |
|||
If flags(i) Then cant += 1: Print i; |
|||
Next |
|||
Print Chr(10); cant; " numbers which are not the sum of distinct squares." |
|||
Sleep</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 |
|||
31 numbers which are not the sum of distinct squares.</pre> |
|||
==={{header|Gambas}}=== |
|||
<syntaxhighlight lang="vbnet">Public flags[1000000] As Boolean |
|||
Public Sub Main() |
|||
Dim limite As Integer = 1e6, cant As Integer = 0, i As Integer |
|||
For i = 0 To limite - 1 |
|||
flags[i] = True |
|||
Next |
|||
For i = 0 To limite - 1 |
|||
If i < limite Then flags[SumSq(i)] = False |
|||
Next |
|||
For i = 0 To Sqr(limite) - 1 |
|||
If flags[i] Then |
|||
cant += 1 |
|||
Print i; " "; |
|||
End If |
|||
Next |
|||
Print Chr(10); cant; " numbers which are not the sum of distinct squares." |
|||
End |
|||
Function SumSq(num As Integer) As Integer |
|||
Dim n As Integer = 1, suma As Integer = 0, Sq As Integer |
|||
While num |
|||
If num And 1 Then |
|||
Sq = n * n |
|||
suma += Sq |
|||
End If |
|||
num = num Shr 1 |
|||
n += 1 |
|||
Wend |
|||
Return suma |
|||
End Function</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as FreeBASIC entry.</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |