Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

m
imported>Maxima enthusiast
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 3 users not shown)
Line 292:
first 15 terms: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">UPTO = 15
i = 2
nfound = 1
 
print 1; " "; #special case
 
while nfound < UPTO
n = divisors(i)
if n = nfound + 1 then
nfound += 1
print i; " ";
end if
i += 1
end while
end
 
function divisors(n)
#find the number of divisors of an integer
r = 2
for i = 2 to n\2
if n mod i = 0 then r += 1
next i
return r
end function</syntaxhighlight>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim UPTO As Integer = 15, i As Integer = 2
Dim n As Integer, nfound As Integer = 1
Print 1; " "; 'special case
While nfound < UPTO
n = divisors(i)
If n = nfound + 1 Then
nfound += 1
Print i; " ";
End If
i += 1
Wend
End Sub
 
Function divisors(n As Integer) As Integer
'find the number of divisors of an integer
 
Dim r As Integer = 2, i As Integer
For i = 2 To n \ 2
If n Mod i = 0 Then r += 1
Next
Return r
 
End Function</syntaxhighlight>
 
==={{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, found
 
UPTO = 15
i = 2
nfound = 1
 
Print("1 ") ;special case
 
While nfound < UPTO
n = divisors(i)
If n = nfound + 1:
nfound + 1
Print(Str(i) + " ")
EndIf
i + 1
Wend
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
 
==={{header|QBasic}}===
{{trans|FreeBASIC}}
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">FUNCTION divisors (n)
'find the number of divisors of an integer
r = 2
FOR i = 2 TO n \ 2
IF n MOD i = 0 THEN r = r + 1
NEXT i
divisors = r
END FUNCTION
 
UPTO = 15
i = 2
nfound = 1
 
PRINT 1; 'special case
 
WHILE nfound < UPTO
n = divisors(i)
IF n = nfound + 1 THEN
nfound = nfound + 1
PRINT i;
END IF
i = i + 1
WEND</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{trans|FreeBASIC}}
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="vb">UPTO = 15
i = 2
nfound = 1
 
print 1; " "; 'special case
 
while nfound < UPTO
n = divisors(i)
if n = nfound + 1 then
nfound = nfound + 1
print i; " ";
end if
i = i + 1
wend
print
end
 
function divisors(n)
'find the number of divisors of an integer
r = 2
for i = 2 to n / 2
if n mod i = 0 then r = r + 1
next i
divisors = r
end function</syntaxhighlight>
 
==={{header|XBasic}}===
{{trans|FreeBASIC}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "program name"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
DECLARE FUNCTION divisors (n)
 
FUNCTION Entry ()
UPTO = 15
i = 2
nfound = 1
 
PRINT 1; 'special case
 
DO WHILE nfound < UPTO
n = divisors(i)
IF n = nfound + 1 THEN
INC nfound
PRINT i;
END IF
INC i
LOOP
END FUNCTION
 
FUNCTION divisors (n)
'find the number of divisors of an integer
r = 2
FOR i = 2 TO n / 2
IF n MOD i = 0 THEN INC r
NEXT i
RETURN r
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">UPTO = 15
i = 2
nfound = 1
 
print 1, " "; //special case
 
while nfound < UPTO
n = divisors(i)
if n = nfound + 1 then
nfound = nfound + 1
print i, " ";
fi
i = i + 1
end while
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|C}}==
Line 507 ⟶ 724:
<pre>The first 15 terms of the sequence are:
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight>
func ndivs n .
i = 1
while i <= sqrt n
if n mod i = 0
cnt += 2
if i = n div i
cnt -= 1
.
.
i += 1
.
return cnt
.
n = 1
while n <= 15
i += 1
if n = ndivs i
write i & " "
n += 1
.
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 521 ⟶ 764:
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 4632 65536 65572 262144 262192 263169 269312 4194304 4194306 4477456 4493312 4498641 4498752
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: io kernel math math.primes.factors prettyprint sequences ;
Line 947 ⟶ 1,191:
[1,2,4,6,16,18,64,66,100,112,1024,1035,4096,4288,4624]
</pre>
 
=={{header|MiniScript}}==
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
divisors = function(n)
divs = {1: 1}
divs[n] = 1
i = 2
while i * i <= n
if n % i == 0 then
divs[i] = 1
divs[n / i] = 1
end if
i += 1
end while
return divs.indexes
end function
 
counts = []
j = 1
for i in range(1, 15)
while divisors(j).len != i
j += 1
end while
counts.push(j)
end for
 
print "The first 15 terms in the sequence are:"
print counts.join(", ")
</syntaxhighlight>
{{out}}
<pre>
The first 15 terms in the sequence are:
1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624</pre>
 
=={{header|Nim}}==
Line 1,610 ⟶ 1,888:
{{trans|Phix}}
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var limit = 24
9,476

edits