Attractive numbers: Difference between revisions

no edit summary
(Added Arturo implementation)
No edit summary
Line 2,250:
102 105 106 108 110 111 112 114 115 116 117 118 119 120
</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>#MAX=120
Dim prime.b(#MAX)
FillMemory(@prime(),#MAX,#True,#PB_Byte) : FillMemory(@prime(),2,#False,#PB_Byte)
For i=2 To Int(Sqr(#MAX)) : n=i*i : While n<#MAX : prime(n)=#False : n+i : Wend : Next
 
Procedure.i pfCount(n.i)
Shared prime()
If n=1 : ProcedureReturn 0 : EndIf
If prime(n) : ProcedureReturn 1 : EndIf
count=0 : f=2
Repeat
If n%f=0 : count+1 : n/f
If n=1 : ProcedureReturn count : EndIf
If prime(n) : f=n : EndIf
ElseIf f>=3 : f+2
Else : f=3
EndIf
ForEver
EndProcedure
 
OpenConsole()
PrintN("The attractive numbers up to and including "+Str(#MAX)+" are:")
For i=1 To #MAX
If prime(pfCount(i))
Print(RSet(Str(i),4)) : count+1 : If count%20=0 : PrintN("") : EndIf
EndIf
Next
PrintN("") : Input()</lang>
{{out}}
<pre>The attractive numbers up to and including 120 are:
4 6 8 9 10 12 14 15 18 20 21 22 25 26 27 28 30 32 33 34
35 38 39 42 44 45 46 48 49 50 51 52 55 57 58 62 63 65 66 68
69 70 72 74 75 76 77 78 80 82 85 86 87 91 92 93 94 95 98 99
102 105 106 108 110 111 112 114 115 116 117 118 119 120</pre>
 
=={{header|Python}}==
164

edits