Untouchable numbers: Difference between revisions
Added FreeBASIC
m (→{{header|C}}: Runs quicker if compiled without any optimizations (used -O3 before).) |
(Added FreeBASIC) |
||
(One intermediate revision by one other user not shown) | |||
Line 500:
readln;
end.</syntaxhighlight>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">Const max_untouchable = 1e6
Dim Shared untouchable(1 To max_untouchable) As Uinteger
For i As Uinteger = 1 To Ubound(untouchable)
untouchable(i) = True
Next i
Sub show_untouchable_statistics()
Dim As Uinteger i, cnt = 0
For i = 1 To Ubound(untouchable)
If untouchable(i) Then cnt += 1
If i = 10 Orelse i = 100 Orelse i = 1000 Orelse i = 10000 Orelse i = 1e5 Then
Print Using "###,### untouchable numbers were found <= #,###,###"; cnt; i
End If
Next i
End Sub
Sub print_untouchables(n As Uinteger)
Print Using "List of untouchable numbers <= #,###:"; n
Dim As Uinteger i, cnt = 0
For i = 1 To n
If untouchable(i) Then
Print Using "##,###"; i;
cnt += 1
Print Iif(cnt Mod 16 = 0, !"\n", " ");
End If
Next i
Print: Print
Print Using "###,### untouchable numbers were found <= #,###,###"; cnt; n
End Sub
Dim As Uinteger i, j
untouchable(1) = False
untouchable(3) = False
For i = 7 To Ubound(untouchable) Step 2
untouchable(i) = False
Next i
Dim Shared spd(1 To max_untouchable * 64) As Uinteger
Dim As Uinteger ub = Ubound(spd)
For i = 1 To ub
spd(i) = 1
Next i
For i = 2 To ub
For j = i + i To ub Step i
spd(j) += i
Next j
Next i
For i = 1 To ub
If spd(i) <= Ubound(untouchable) Then untouchable(spd(i)) = False
Next i
' Show the untouchable numbers up to 2000
print_untouchables(2000)
' Show the counts of untouchable numbers
show_untouchable_statistics()
Sleep</syntaxhighlight>
=={{header|F_Sharp|F#}}==
Line 1,893 ⟶ 1,953:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
Line 1,899 ⟶ 1,958:
===Version 1===
Run time about 70 seconds on my Core i7 machine.
<syntaxhighlight lang="
import "./
var sieve = Fn.new { |n|
Line 1,924 ⟶ 1,982:
System.print("List of untouchable numbers <= 2,000:")
System.print()
Fmt.print("$,6d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })
Line 1,978 ⟶ 2,034:
Run time for untouchable numbers up to 100,000 (m = 14) is now only 1.4 seconds and 1,000,000 (m = 63) is reached in 132 seconds.
<syntaxhighlight lang="
import "./
var limit = 1e6
Line 2,006 ⟶ 2,061:
}
System.print("List of untouchable numbers <= 2,000:")
System.print()
Fmt.print("$,7d untouchable numbers were found <= 2,000", untouchable.count { |n| n <= 2000 })
|