Sequence: smallest number with exactly n divisors: Difference between revisions

Content added Content deleted
(Add SETL)
(Added PureBasic and Yabasic)
Line 242: Line 242:
first 15 terms: 1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144
first 15 terms: 1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144
</pre>
</pre>

=={{header|BASIC}}==
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">Procedure.i divisors(n)
;find the number of divisors of an integer
Define.i r, i
r = 2
For i = 2 To n/2
If n % i = 0: r + 1
EndIf
Next i
ProcedureReturn r
EndProcedure

OpenConsole()
Define.i UPTO, i, n, nfound

UPTO = 15
i = 2
nfound = 1
Dim sfound.i(UPTO)
sfound(1) = 1

While nfound < UPTO
n = divisors(i)
If n <= UPTO And sfound(n) = 0:
nfound + 1
sfound(n) = i
EndIf
i + 1
Wend

Print("1 ") ;special case
For i = 2 To UPTO
Print(Str(sfound(i)) + " ")
Next i

PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>

==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">UPTO = 15
i = 2
nfound = 1
dim sfound(UPTO)
sfound(1) = 1

while nfound < UPTO
n = divisors(i)
if n <= UPTO and sfound(n) = 0 then
nfound = nfound + 1
sfound(n) = i
fi
i = i + 1
end while

print 1, " "; //special case
for i = 2 to UPTO
print sfound(i), " ";
next i
print
end

sub divisors(n)
local r, i
//find the number of divisors of an integer
r = 2
for i = 2 to n / 2
if mod(n, i) = 0 r = r + 1
next i
return r
end sub</syntaxhighlight>


=={{header|BCPL}}==
=={{header|BCPL}}==