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

m
m (→‎{{header|Phix}}: added limit of 32 results)
m (→‎{{header|Wren}}: Minor tidy)
 
(9 intermediate revisions by 8 users not shown)
Line 22:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F divisors(n)
V divs = [1]
L(ii) 2 .< Int(n ^ 0.5) + 3
Line 49:
 
L(item) sequence(15)
print(item)</langsyntaxhighlight>
 
{{out}}
Line 72:
=={{header|Action!}}==
Calculations on a real Atari 8-bit computer take quite long time. It is recommended to use an emulator capable with increasing speed of Atari CPU.
<langsyntaxhighlight Actionlang="action!">CARD FUNC CountDivisors(CARD a)
CARD i,count
 
Line 105:
PrintC(a)
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sequence_smallest_number_greater_than_previous_term_with_exactly_n_divisors.png Screenshot from Atari 8-bit computer]
Line 114:
=={{header|Ada}}==
{{trans|Go}}
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
procedure Show_Sequence is
Line 153:
begin
Show (15);
end Show_Sequence;</langsyntaxhighlight>
 
{{out}}
Line 161:
=={{header|ALGOL 68}}==
{{trans|Go}} with a small optimisation.
<langsyntaxhighlight lang="algol68">BEGIN
 
PROC count divisors = ( INT n )INT:
Line 183:
OD
 
END</langsyntaxhighlight>
{{out}}
<pre>
Line 191:
=={{header|ALGOL W}}==
{{Trans|Go}}...via Algol 68 and with a small optimisation.
<langsyntaxhighlight lang="pascal">begin
integer max, next, i;
 
Line 219:
end;
write()
end.</langsyntaxhighlight>
{{out}}
<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|Arturo}}==
 
<syntaxhighlight lang="rebol">i: new 0
next: new 1
MAX: 15
while [next =< MAX][
if next = size factors i [
prints ~"|i| "
inc 'next
]
inc 'i
]
print ""</syntaxhighlight>
 
{{out}}
 
<pre>1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre>
 
=={{header|AutoHotkey}}==
{{trans|Go}}
<langsyntaxhighlight AutoHotkeylang="autohotkey">MAX := 15
next := 1, i := 1
while (next <= MAX)
Line 240 ⟶ 258:
count += (A_Index = n/A_Index) ? 1 : 2
return count
}</langsyntaxhighlight>
Outputs:<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|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f SEQUENCE_SMALLEST_NUMBER_GREATER_THAN_PREVIOUS_TERM_WITH_EXACTLY_N_DIVISORS.AWK
# converted from Kotlin
Line 269 ⟶ 287:
return(count)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
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}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
#define MAX 15
Line 305 ⟶ 540:
printf("\n");
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 315 ⟶ 550:
=={{header|C++}}==
{{trans|C}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
#define MAX 15
Line 344 ⟶ 579:
cout << endl;
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 353 ⟶ 588:
===Alternative===
{{Trans|Pascal}}
More terms and quicker than the straightforward C version above. [https://tio.run/##bVJNb9NAFLz7V0yLGu1ihzopJ38EIbgiJMSBG3J3N84KZ@1417QI5a8T3tuQNqm42W/emxnPWA3DvFXqcHhlneombVApH7TtV8nZZDP2jibJ5K1r4Zqt8UOjDGizKI5omSSqdz7AuoBP77@hxt2yTJBMztvWGR2B1oSP9qfVZvQfXBAXmJP4nQAXM800GXYZ9BfjM4zG02RBvHjY2M5AXAmHGRaSjuGwWjHKa2laYv@8JjReQ0tUddTBjmgcbqFL2DWI44a1auQMshbhOcsAuj@N0pqZSzqssSuJ47Zmgv1J5IzleIpomM74nBc1vyz5aTRhGh1RXZFjvIuLVUWPxVFjnyQcwLaxTrCni1hsBvcYMlCWFCNrDSPN1@L668ZgbUfq4UajccHOCaG6MHSTRzOaAtcZ9xMdNlPoqUT6HB9Mo399V12vfhSF6x@EpGQ4pMcQE48xxI/ivMRRmZAXjVoqoj5eseuTLTJDsvYplsiRpry2wluJ2QziBRNhkWop5b8jRENiwTkxjHnsfc7u9rCx8acqCKauTx965mPryYmgVyn0NDbB9q7S/XTfmZX4TwpE74N8o/qJPEn6iRZ5nksi3R8Of9S6a1p/mH@@@ws Try It Online!]<langsyntaxhighlight lang="cpp">#include <cstdio>
#include <chrono>
 
Line 374 ⟶ 609:
i = (1 << (nxt - 1)) - 1; } i++; } while (nxt <= MAX);
printf("%d ms", (int)(duration<double>(steady_clock::now() - st).count() * 1000));
}</langsyntaxhighlight>
{{out}}
<pre>The first 32 anti-primes plus are: 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 268435456 268437200 1073741824 1073741830 223 ms</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
{These routines would normally be in a library, but the shown here for clarity}
 
function GetAllProperDivisors(N: Integer;var IA: TIntegerDynArray): integer;
{Make a list of all the "proper dividers" for N}
{Proper dividers are the of numbers the divide evenly into N}
var I: integer;
begin
SetLength(IA,0);
for I:=1 to N-1 do
if (N mod I)=0 then
begin
SetLength(IA,Length(IA)+1);
IA[High(IA)]:=I;
end;
Result:=Length(IA);
end;
 
 
function GetAllDivisors(N: Integer;var IA: TIntegerDynArray): integer;
{Make a list of all the "proper dividers" for N, Plus N itself}
begin
Result:=GetAllProperDivisors(N,IA)+1;
SetLength(IA,Length(IA)+1);
IA[High(IA)]:=N;
end;
 
 
procedure SmallestWithNDivisors(Memo: TMemo);
var N,Count: integer;
var IA: TIntegerDynArray;
begin
Count:=1;
for N:=1 to high(Integer) do
if Count=GetAllDivisors(N,IA) then
begin
Memo.Lines.Add(IntToStr(Count)+' - '+IntToStr(N));
Inc(Count);
if Count>15 then break;
end;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1 - 1
2 - 2
3 - 4
4 - 6
5 - 16
6 - 18
7 - 64
8 - 66
9 - 100
10 - 112
11 - 1024
12 - 1035
13 - 4096
14 - 4288
15 - 4624
 
Elapsed Time: 58.590 ms.
 
</pre>
 
 
=={{header|Dyalect}}==
Line 382 ⟶ 691:
{{trans|Go}}
 
<langsyntaxhighlight lang="dyalect">func countDivisors(n) {
var count = 0
var i = 1
Line 409 ⟶ 718:
}
 
print()</langsyntaxhighlight>
 
{{out}}
Line 415 ⟶ 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#}}==
===First 28 are easy with a Naive implementation===
<langsyntaxhighlight lang="fsharp">
// Nigel Galloway: November 19th., 2017
let fN g=[1..(float>>sqrt>>int)g]|>List.fold(fun Σ n->if g%n>0 then Σ else if g/n=n then Σ+1 else Σ+2) 0
Line 424 ⟶ 759:
 
A069654 |> Seq.take 28|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
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}}==
<langsyntaxhighlight lang="factor">USING: io kernel math math.primes.factors prettyprint sequences ;
 
: next ( n num -- n' num' )
Line 438 ⟶ 774:
[ 2 1 ] dip [ [ next ] keep ] replicate 2nip ;
 
"The first 15 terms of the sequence are:" print 15 A069654 .</langsyntaxhighlight>
{{out}}
<pre>
Line 446 ⟶ 782:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define UPTO 15
 
function divisors(byval n as ulongint) as uinteger
Line 471 ⟶ 807:
wend
print
end</langsyntaxhighlight>
{{out}}<pre> 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 503 ⟶ 839:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 511 ⟶ 847:
</pre>
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Text.Printf (printf)
 
sequence_A069654 :: [(Int,Int)]
Line 522 ⟶ 858:
 
main :: IO ()
main = mapM_ (uncurry $ printf "a(%2d)=%5d\n") $ take 15 sequence_A069654</langsyntaxhighlight>
{{out}}
<pre>a( 1)= 1
Line 542 ⟶ 878:
 
=={{header|J}}==
<syntaxhighlight lang="j">
<lang j>
sieve=: 3 :0
NB. sieve y returns a vector of y boxes.
Line 560 ⟶ 896:
(</.~ {."1) (,. i.@:#)tally
)
</syntaxhighlight>
</lang>
 
<pre>
Line 688 ⟶ 1,024:
=={{header|Java}}==
{{trans|C}}
<langsyntaxhighlight lang="java">public class AntiPrimesPlus {
 
static int count_divisors(int n) {
Line 714 ⟶ 1,050:
System.out.println();
}
}</langsyntaxhighlight>
 
{{out}}
Line 726 ⟶ 1,062:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
<lang jq>
# The number of prime factors (as in prime factorization)
def numfactors:
Line 746 ⟶ 1,082:
 
"First 15 terms of OEIS sequence A069654: ",
[limit(15; A06954)]</langsyntaxhighlight>
{{out}}
<pre>
Line 756 ⟶ 1,092:
=={{header|Julia}}==
{{trans|Perl}}
<langsyntaxhighlight lang="julia">using Primes
 
function numfactors(n)
Line 782 ⟶ 1,118:
 
A06954(15)
</langsyntaxhighlight>{{out}}
<pre>
First 15 terms of OEIS sequence A069654:
Line 790 ⟶ 1,126:
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">// Version 1.3.21
 
const val MAX = 15
Line 818 ⟶ 1,154:
}
println()
}</langsyntaxhighlight>
 
{{output}}
Line 827 ⟶ 1,163:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">res = {#, DivisorSigma[0, #]} & /@ Range[100000];
highest = 0;
filter = {};
Line 838 ⟶ 1,174:
{r, res}
]
Take[filter, 15]</langsyntaxhighlight>
{{out}}
<pre>{1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
sngptend(n):=block([i:1,count:1,result:[]],
while count<=n do (if length(listify(divisors(i)))=count then (result:endcons(i,result),count:count+1),i:i+1),
result)$
 
/* Test case */
sngptend(15);
</syntaxhighlight>
{{out}}
<pre>
[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}}==
<langsyntaxhighlight lang="nim">import strformat
 
const MAX = 15
Line 866 ⟶ 1,250:
inc next
inc i
write(stdout, "\n")</langsyntaxhighlight>
{{out}}
<pre>
Line 879 ⟶ 1,263:
I think of next = 33 aka 11*3 with the solution 1031^2 * 2^10=1,088,472,064 with a big distance to next= 32 => 1073741830.<BR>
[https://tio.run/##fVRdb9owFH3Pr7gPk0hYWCG0e2hKJcbHhtQCapm0vSCZxAGvwaa2U1ZV/PWxazsQ2k7jIeR@n3t8HLH4RRPd2BCVkLyRbZL9fiPFUpI1dLlmU8nWVE3zQsXey4fRsD8YwnDa23kALx9uJ/0B9Gm@WbEdRgc39wMX6E6ns5/TAfQm4/vJzWAHZ2eQ2jyTNu6PhjuvUFRhsnpWhWa5CtdEr2IvEVxpdN92f0CnHcUeeFnBE80EhyXVffbEUipVj2ufX35nXLejoPyPPZzyOgcWz5Aak/ElcMA0AUwr2JitICOJFlKZMvJAMN6BKLpomr95q96eR/WLeRtWRIHf@tgK6n5kn218Ysq564yDvCciEbIxw8dC6BBX1eSOqlBSpeESDvgWdMk4ZqK7yDHQgZZZEJAeUwzGE8VoKbohkmjYMr0ShbatFVKAqdsVyymMhfYnaerzIIBUoPtL2RpwDezC4f7bne2OP8YT340MjIPy9DA1k2INXGwB2RU8fwaRpsCL9cJs5TayoNrxcbKvHqVvAsFVh78bjtzfCoQVVmQYDoISSAaWkQ40Qa@oK6mKAQ7EmZnNuHRKuqFEl4bb5pRgu5YLHXMsB2b628D/8QEUKPncgby6riBUDB7PtixxZB5gmabRCclIMe6cE2znxAYiMzosFYgJoyHaOKpVEVKpw73VUTnlmTmhzZqoqRHXn8/NCBZy@luHuBkK/r3WtpJpmnO/Nluh4plEKLUQb1dYA4LLNiwQxIM3HIiklzULf9bE8V@pnrHkoSeK46yDZsHMPBonJ@RgmMib28pKwnBhl9NxPf6pAwvaZ4ixFpyegak4Oiy3tseBT9vMCdnaPnSuYS2URkcEwdzWN1qBKVAiL7S7UiUsG4VrOA@gO@6D//ZzY2abb0NQYba4LA2gVjkc@zdaMX5UmJmDsCVdU65pCiTTVG6JTNV77Th@nP7GDgieUlyd4Mmr//pkGrMmMrVWhivs@cnb7/8kWU6Wat@YRH8B Try it online!]
<langsyntaxhighlight lang="pascal">program AntiPrimesPlus;
{$IFDEF FPC}
{$MODE Delphi}
Line 949 ⟶ 1,333:
writeln;
writeln(GetTickCount64-T0,' ms');
end.</langsyntaxhighlight>
{{out}}
<pre>The first 32 anti-primes plus are:
Line 957 ⟶ 1,341:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use ntheory 'divisors';
Line 968 ⟶ 1,352:
print("$l "), $m = $l, last if $n == divisors($l);
}
}</langsyntaxhighlight>
{{out}}
 
Line 976 ⟶ 1,360:
=={{header|Phix}}==
Uses the optimisation trick from pascal, of n:=power(2,next-1) when next is a prime>4.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span>
Line 994 ⟶ 1,378:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first %d terms are: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,014 ⟶ 1,398:
=={{header|PL/M}}==
{{Trans|Go}} via Algol 68
<langsyntaxhighlight lang="pli">100H: /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */
 
/* CP/M BDOS SYSTEM CALL */
Line 1,064 ⟶ 1,448:
END;
 
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 1,079 ⟶ 1,463:
Note the use of text in column 81 onwards to hide the PL/I specifics from the PL/M compiler.
{{Trans|PL/M}}
<langsyntaxhighlight lang="pli"> /* FIND THE SMALLEST NUMBER > THE PREVIOUS ONE WITH EXACTLY N DIVISORS */
 
sequence_100H: procedure options (main);
Line 1,159 ⟶ 1,543:
END;
 
EOF: end sequence_100H;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,166 ⟶ 1,550:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
def divisors(n):
divs = [1]
Line 1,197 ⟶ 1,581:
for item in sequence(15):
print(item)
</syntaxhighlight>
</lang>
<b>Output:</b>
<syntaxhighlight lang="python">
<lang Python>
1
2
Line 1,215 ⟶ 1,599:
4288
4624
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
Line 1,221 ⟶ 1,605:
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
 
<langsyntaxhighlight Quackerylang="quackery"> [ stack ] is terms ( --> s )
 
[ temp put
Line 1,240 ⟶ 1,624:
dip 2drop ] is task ( n --> [ )
 
15 task echo</langsyntaxhighlight>
 
{{out}}
Line 1,247 ⟶ 1,631:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">#Need to add 1 to account for skipping n. Not the most efficient way to count divisors, but quite clear.
divisorCount <- function(n) length(Filter(function(x) n %% x == 0, seq_len(n %/% 2))) + 1
A06954 <- function(terms)
Line 1,260 ⟶ 1,644:
out
}
print(A06954(15))</langsyntaxhighlight>
{{out}}
<pre>[1] 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624</pre>
Line 1,268 ⟶ 1,652:
{{works with|Rakudo|2019.03}}
 
<syntaxhighlight lang="raku" perl6line>sub div-count (\x) {
return 2 if x.is-prime;
+flat (1 .. x.sqrt.floor).map: -> \d {
Line 1,280 ⟶ 1,664:
put "First $limit terms of OEIS:A069654";
put (1..$limit).map: -> $n { my $ = $m = first { $n == .&div-count }, $m..Inf };
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,293 ⟶ 1,677:
 
Optimization was included when examining &nbsp; ''even'' &nbsp; or &nbsp; ''odd'' &nbsp; index numbers &nbsp; (determine how much to increment the &nbsp; '''do''' &nbsp; loop).
<langsyntaxhighlight lang="rexx">/*REXX program finds and displays N numbers of the "anti─primes plus" sequence. */
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N= 15 /*Not specified? Then use the default.*/
Line 1,326 ⟶ 1,710:
else if k*k>x then leave /*only divide up to the √ x */
end /*k*/ /* [↑] this form of DO loop is faster.*/
return # + 1 /*bump "proper divisors" to "divisors".*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,348 ⟶ 1,732:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : ANti-primes
 
Line 1,386 ⟶ 1,770:
next
return ansum
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,398 ⟶ 1,782:
done...
</pre>
 
=={{header|RPL}}==
{{works with|HP|49g}}
≪ {1}
2 ROT '''FOR''' j
DUP DUP SIZE GET
'''DO''' 1 + '''UNTIL''' DUP DIVIS SIZE j == '''END'''
+
'''NEXT '''
≫ '<span style="color:blue">TASK</span>' STO
 
15 <span style="color:blue">TASK</span>
{{out}}
<pre>
1: {1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624}
</pre>
Runs in 10 minutes 55 on a HP-50g.
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'prime'
def num_divisors(n)
Line 1,417 ⟶ 1,818:
 
p seq.take(15)
</syntaxhighlight>
</lang>
{{out}}
<pre>[1, 2, 4, 6, 16, 18, 64, 66, 100, 112, 1024, 1035, 4096, 4288, 4624]
Line 1,423 ⟶ 1,824:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func n_divisors(n, from=1) {
from..Inf -> first_by { .sigma0 == n }
}
Line 1,429 ⟶ 1,830:
with (1) { |from|
say 15.of { from = n_divisors(_+1, from) }
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,437 ⟶ 1,838:
=={{header|Swift}}==
Includes an optimization borrowed from the Pascal example above.
<langsyntaxhighlight lang="swift">// See https://en.wikipedia.org/wiki/Divisor_function
func divisorCount(number: Int) -> Int {
var n = number
Line 1,477 ⟶ 1,878:
n += 1
}
print()</langsyntaxhighlight>
 
{{out}}
Line 1,487 ⟶ 1,888:
{{trans|Phix}}
{{libheader|Wren-math}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
 
var limit = 24
Line 1,503 ⟶ 1,904:
}
System.print("The first %(limit) terms are:")
System.print(res)</langsyntaxhighlight>
 
{{out}}
Line 1,512 ⟶ 1,913:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Divs(N); \Count divisors of N
int N, D, C;
[C:= 0;
Line 1,533 ⟶ 1,934:
An:= An+1;
];
]</langsyntaxhighlight>
 
{{out}}
Line 1,541 ⟶ 1,942:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn countDivisors(n)
{ [1..(n).toFloat().sqrt()] .reduce('wrap(s,i){ s + (if(0==n%i) 1 + (i!=n/i)) },0) }</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">n:=15;
println("The first %d anti-primes plus are:".fmt(n));
(1).walker(*).tweak(
fcn(n,rn){ if(rn.value==countDivisors(n)){ rn.inc(); n } else Void.Skip }.fp1(Ref(1)))
.walk(n).concat(" ").println();</langsyntaxhighlight>
{{out}}
<pre>
9,476

edits