Arithmetic numbers: Difference between revisions

Add Modula-2
(Add APL)
(Add Modula-2)
(12 intermediate revisions by 5 users not shown)
Line 288:
The 10000th arithmetic number: 12953
Of the first 10000 arithmetic numbers, 8458 are composite.</pre>
 
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">on isArithmetic(n)
if (n < 4) then
if (n < 0) then return {arithmetic:false, composite:missing value}
return {arithmetic:(n mod 2 = 1), composite:false}
end if
set factorSum to 1 + n
set factorCount to 2
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set factorSum to factorSum + limit
set factorCount to 3
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i = 0) then
set factorSum to factorSum + i + n div i
set factorCount to factorCount + 2
end if
end repeat
return {arithmetic:(factorSum mod factorCount = 0), composite:(factorCount > 2)}
end isArithmetic
 
on task()
set output to {linefeed & "The first 100 arithmetic numbers are:"}
set {n, hitCount, compositeCount, pad} to {0, 0, 0, " "}
repeat 10 times
set row to {}
set targetCount to hitCount + 10
repeat until (hitCount = targetCount)
set n to n + 1
tell isArithmetic(n) to if (its arithmetic) then
set hitCount to hitCount + 1
if (its composite) then set compositeCount to compositeCount + 1
set row's end to text -4 thru -1 of (pad & n)
end if
end repeat
set output's end to join(row, "")
end repeat
repeat with targetCount in {1000, 10000, 100000, 1000000}
repeat while (hitCount < targetCount)
set n to n + 1
tell isArithmetic(n) to if (its arithmetic) then
set hitCount to hitCount + 1
if (its composite) then set compositeCount to compositeCount + 1
end if
end repeat
set output's end to (linefeed & "The " & targetCount & "th arithmetic number is " & n) & ¬
(linefeed & "(" & compositeCount & " composite numbers up to here)")
end repeat
return join(output, linefeed)
end task
 
on join(lst, delim)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set txt to lst as text
set AppleScript's text item delimiters to astid
return txt
end join
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"
The first 100 arithmetic numbers are:
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
The 1000th arithmetic number is 1361
(782 composite numbers up to here)
 
The 10000th arithmetic number is 12953
(8458 composite numbers up to here)
 
The 100000th arithmetic number is 125587
(88219 composite numbers up to here)
 
The 1000000th arithmetic number is 1228663
(905043 composite numbers up to here)"</syntaxhighlight>
 
=={{header|ARM Assembly}}==
Line 1,057 ⟶ 1,149:
Number of composite arithmetic numbers <= 1228663: 905043
</pre>
 
=={{header|C#}}==
{{trans|Java}}
<syntaxhighlight lang="C#">
using System;
using System.Collections.Generic;
using System.Linq;
 
public class ArithmeticNumbers
{
public static void Main(string[] args)
{
int arithmeticCount = 0;
int compositeCount = 0;
int n = 1;
 
while (arithmeticCount <= 1_000_000)
{
var factors = Factors(n);
int sum = factors.Sum();
if (sum % factors.Count == 0)
{
arithmeticCount++;
if (factors.Count > 2)
{
compositeCount++;
}
if (arithmeticCount <= 100)
{
Console.Write($"{n,3}{(arithmeticCount % 10 == 0 ? "\n" : " ")}");
}
if (new[] { 1_000, 10_000, 100_000, 1_000_000 }.Contains(arithmeticCount))
{
Console.WriteLine();
Console.WriteLine($"{arithmeticCount}th arithmetic number is {n}");
Console.WriteLine($"Number of composite arithmetic numbers <= {n}: {compositeCount}");
}
}
n++;
}
}
 
private static HashSet<int> Factors(int number)
{
var result = new HashSet<int> { 1, number };
int i = 2;
int j;
while ((j = number / i) >= i)
{
if (i * j == number)
{
result.Add(i);
result.Add(j);
}
i++;
}
return result;
}
}
</syntaxhighlight>
{{out}}
<pre>
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
1000th arithmetic number is 1361
Number of composite arithmetic numbers <= 1361: 782
 
10000th arithmetic number is 12953
Number of composite arithmetic numbers <= 12953: 8458
 
100000th arithmetic number is 125587
Number of composite arithmetic numbers <= 125587: 88219
 
1000000th arithmetic number is 1228663
Number of composite arithmetic numbers <= 1228663: 905043
 
</pre>
 
 
=={{header|C++}}==
Line 1,144 ⟶ 1,323:
sys 0m0.003s</pre>
 
=={{header|FactorCowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang="factor">USING: combinators formatting grouping io kernel lists
lists.lazy math math.functions math.primes math.primes.factors
math.statistics math.text.english prettyprint sequences
tools.memory.private ;
 
const MAX := 13000;
: arith? ( n -- ? ) divisors mean integer? ;
: larith ( -- list ) 1 lfrom [ arith? ] lfilter ;
: arith ( m -- seq ) larith ltake list>array ;
: composite? ( n -- ? ) dup 1 > swap prime? not and ;
: ordinal ( n -- str ) [ commas ] keep ordinal-suffix append ;
 
var divisorSum: uint16[MAX+1];
: info. ( n -- )
var divisorCount: uint8[MAX+1];
{
[ ordinal "%s arithmetic number: " printf ]
[ arith dup last commas print ]
[ commas "Number of composite arithmetic numbers <= %s: " printf ]
[ drop [ composite? ] count commas print nl ]
} cleave ;
 
sub CalculateDivisorSums() is
MemZero(&divisorSum[0] as [uint8], @bytesof divisorSum);
MemZero(&divisorCount[0] as [uint8], @bytesof divisorCount);
 
var div: @indexof divisorSum := 1;
"First 100 arithmetic numbers:" print
while div <= MAX loop
100 arith 10 group simple-table. nl
var num := div;
{ 3 4 5 6 } [ 10^ info. ] each</syntaxhighlight>
while num <= MAX loop
{{out}}
divisorSum[num] := divisorSum[num] + div;
<pre>
divisorCount[num] := divisorCount[num] + 1;
First 100 arithmetic numbers:
1 3 5 6 7num := num 11+ 13 14 15 17div;
19 20 21 22 23end 27 29 30 31 33loop;
35 37 38 39 41div := 42div + 43 44 45 461;
end loop;
47 49 51 53 54 55 56 57 59 60
end sub;
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
sub NextArithmetic(n: uint16): (r: uint16) is
1,000th arithmetic number: 1,361
r := n + 1;
Number of composite arithmetic numbers <= 1,000: 782
while divisorSum[r] % divisorCount[r] as uint16 != 0 loop
r := r + 1;
end loop;
end sub;
 
sub Composite(n: uint16): (r: uint8) is
10,000th arithmetic number: 12,953
r := 0;
Number of composite arithmetic numbers <= 10,000: 8,458
if n>1 and divisorSum[n] != n+1 then
r := 1;
end if;
end sub;
 
var current: uint16 := 0;
100,000th arithmetic number: 125,587
var nth: uint16 := 0;
Number of composite arithmetic numbers <= 100,000: 88,219
var composites: uint16 := 0;
 
CalculateDivisorSums();
1,000,000th arithmetic number: 1,228,663
Number of composite arithmetic numbers <= 1,000,000: 905,043
</pre>
 
print("First 100 arithmetic numbers:\n");
=={{header|FreeBASIC}}==
while nth < 10000 loop
{{trans|Delphi}}
current := NextArithmetic(current);
<syntaxhighlight lang="freebasic">' Rosetta Code problem: https://rosettacode.org/wiki/Arithmetic_numbers
nth := nth + 1;
' by Jjuanhdez, 06/2022
composites := composites + Composite(current) as uint16;
 
if nth <= 100 then
Dim As Double t0 = Timer
print_i16(current);
Dim As Integer N = 1, ArithCnt = 0, CompCnt = 0
if nth % 5 == 0 then
Dim As Integer Div, DivCnt, Sum, Quot
print_nl();
else
print_char('\t');
end if;
end if;
 
if nth == 1000 or nth == 10000 then
Print "The first 100 arithmetic numbers are:"
print_nl();
Do
Div = 1 : DivCnt = 0 : Sum = 0print_i16(nth);
print(": ");
Do
Quot = N / Divprint_i16(current);
If Quot < Div Then Exit Doprint("\t");
print_i16(composites);
If Quot = Div AndAlso (N Mod Div) = 0 Then 'N is a square
print(" Sum += Quot composites\n");
end if;
DivCnt += 1
end loop;</syntaxhighlight>
Exit Do
End If
If (N Mod Div) = 0 Then
Sum += Div + Quot
DivCnt += 2
End If
Div += 1
Loop
If (Sum Mod DivCnt) = 0 Then 'N is arithmetic
ArithCnt += 1
If ArithCnt <= 100 Then
Print Using "####"; N;
If (ArithCnt Mod 20) = 0 Then Print
End If
If DivCnt > 2 Then CompCnt += 1
Select Case ArithCnt
Case 1e3
Print Using !"\nThe #######th arithmetic number is #####,### up to which ###,### are composite."; ArithCnt; N; CompCnt
Case 1e4, 1e5, 1e6
Print Using "The #######th arithmetic number is #####,### up to which ###,### are composite."; ArithCnt; N; CompCnt
End Select
End If
N += 1
Loop Until ArithCnt >= 1e6
Print !"\nTook"; Timer - t0; " seconds on i5 @3.20 GHz"
Sleep</syntaxhighlight>
{{out}}
<pre>The firstFirst 100 arithmetic numbers are:
1 3 5 3 6 7 115 13 14 15 6 17 19 20 21 22 23 27 29 30 31 337
11 35 37 3813 39 41 4214 43 44 4515 46 47 49 51 53 54 55 56 57 59 6017
19 61 62 6520 66 67 6821 69 70 7122 73 77 78 79 83 85 86 87 89 91 9223
27 93 94 9529 96 97 9930 101 102 103 105 107 10931 110 111 113 114 115 116 118 11933
12335 125 126 127 129 131 13237 133 134 135 137 138 13938 140 141 142 143 145 14739 149 41
42 43 44 45 46
47 49 51 53 54
55 56 57 59 60
61 62 65 66 67
68 69 70 71 73
77 78 79 83 85
86 87 89 91 92
93 94 95 96 97
99 101 102 103 105
107 109 110 111 113
114 115 116 118 119
123 125 126 127 129
131 132 133 134 135
137 138 139 140 141
142 143 145 147 149
 
1000: 1361 782 composites
The 1000th arithmetic number is 1,361 up to which 782 are composite.
The 10000th arithmetic number is 12,953 up to which 8,458 are composite.
The 100000th arithmetic number is 125,587 up to which 88,219 are composite.
The 1000000th arithmetic number is 1,228,663 up to which 905,043 are composite.
 
Took 38.42344779999985 seconds on i5 @3.20 GHz</pre>
 
10000: 12953 8458 composites</pre>
=={{header|Delphi}}==
<syntaxhighlight lang="delphi">
Line 1,333 ⟶ 1,495:
Hit Any Key
</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">word MAX = 13000;
 
[MAX+1]word divisorSum;
[MAX+1]byte divisorCount;
 
proc calculateDivisorSums() void:
word num, div;
for div from 1 by 1 upto MAX do
for num from div by div upto MAX do
divisorSum[num] := divisorSum[num] + div;
divisorCount[num] := divisorCount[num] + 1
od
od
corp
 
proc arithmetic(word n) bool:
divisorSum[n] % divisorCount[n] = 0
corp
 
proc composite(word n) bool:
n > 1 and divisorSum[n] /= n+1
corp
 
proc main() void:
word num, nthArithm, composites;
calculateDivisorSums();
 
writeln("First 100 arithmetic numbers:");
 
num := 0;
composites := 0;
for nthArithm from 1 upto 10000 do
while num := num+1; not arithmetic(num) do od;
if composite(num) then composites := composites + 1 fi;
 
if nthArithm <= 100 then
write(num:5);
if nthArithm % 10 = 0 then writeln() fi
fi;
 
if nthArithm = 1000 or nthArithm = 10000 then
writeln();
writeln("The ",nthArithm,"th arithmetic number is ",num,".");
writeln("Of the first ",nthArithm," arithmetic numbers, ",
composites," are composite.")
fi
od
corp</syntaxhighlight>
{{out}}
<pre>First 100 arithmetic numbers:
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
The 1000th arithmetic number is 1361.
Of the first 1000 arithmetic numbers, 782 are composite.
 
The 10000th arithmetic number is 12953.
Of the first 10000 arithmetic numbers, 8458 are composite.</pre>
 
=={{header|EasyLang}}==
Line 1,376 ⟶ 1,606:
.
</syntaxhighlight>
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang="factor">USING: combinators formatting grouping io kernel lists
lists.lazy math math.functions math.primes math.primes.factors
math.statistics math.text.english prettyprint sequences
tools.memory.private ;
 
: arith? ( n -- ? ) divisors mean integer? ;
: larith ( -- list ) 1 lfrom [ arith? ] lfilter ;
: arith ( m -- seq ) larith ltake list>array ;
: composite? ( n -- ? ) dup 1 > swap prime? not and ;
: ordinal ( n -- str ) [ commas ] keep ordinal-suffix append ;
 
: info. ( n -- )
{
[ ordinal "%s arithmetic number: " printf ]
[ arith dup last commas print ]
[ commas "Number of composite arithmetic numbers <= %s: " printf ]
[ drop [ composite? ] count commas print nl ]
} cleave ;
 
 
"First 100 arithmetic numbers:" print
100 arith 10 group simple-table. nl
{ 3 4 5 6 } [ 10^ info. ] each</syntaxhighlight>
{{out}}
<pre>
First 100 arithmetic numbers:
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
1,000th arithmetic number: 1,361
Number of composite arithmetic numbers <= 1,000: 782
 
10,000th arithmetic number: 12,953
Number of composite arithmetic numbers <= 10,000: 8,458
 
100,000th arithmetic number: 125,587
Number of composite arithmetic numbers <= 100,000: 88,219
 
1,000,000th arithmetic number: 1,228,663
Number of composite arithmetic numbers <= 1,000,000: 905,043
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Delphi}}
<syntaxhighlight lang="freebasic">' Rosetta Code problem: https://rosettacode.org/wiki/Arithmetic_numbers
' by Jjuanhdez, 06/2022
 
Dim As Double t0 = Timer
Dim As Integer N = 1, ArithCnt = 0, CompCnt = 0
Dim As Integer Div, DivCnt, Sum, Quot
 
Print "The first 100 arithmetic numbers are:"
Do
Div = 1 : DivCnt = 0 : Sum = 0
Do
Quot = N / Div
If Quot < Div Then Exit Do
If Quot = Div AndAlso (N Mod Div) = 0 Then 'N is a square
Sum += Quot
DivCnt += 1
Exit Do
End If
If (N Mod Div) = 0 Then
Sum += Div + Quot
DivCnt += 2
End If
Div += 1
Loop
If (Sum Mod DivCnt) = 0 Then 'N is arithmetic
ArithCnt += 1
If ArithCnt <= 100 Then
Print Using "####"; N;
If (ArithCnt Mod 20) = 0 Then Print
End If
If DivCnt > 2 Then CompCnt += 1
Select Case ArithCnt
Case 1e3
Print Using !"\nThe #######th arithmetic number is #####,### up to which ###,### are composite."; ArithCnt; N; CompCnt
Case 1e4, 1e5, 1e6
Print Using "The #######th arithmetic number is #####,### up to which ###,### are composite."; ArithCnt; N; CompCnt
End Select
End If
N += 1
Loop Until ArithCnt >= 1e6
Print !"\nTook"; Timer - t0; " seconds on i5 @3.20 GHz"
Sleep</syntaxhighlight>
{{out}}
<pre>The first 100 arithmetic numbers are:
1 3 5 6 7 11 13 14 15 17 19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46 47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73 77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105 107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135 137 138 139 140 141 142 143 145 147 149
 
The 1000th arithmetic number is 1,361 up to which 782 are composite.
The 10000th arithmetic number is 12,953 up to which 8,458 are composite.
The 100000th arithmetic number is 125,587 up to which 88,219 are composite.
The 1000000th arithmetic number is 1,228,663 up to which 905,043 are composite.
 
Took 38.42344779999985 seconds on i5 @3.20 GHz</pre>
 
=={{header|FutureBasic}}==
Line 1,954 ⟶ 2,294:
100000 125587 88219</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Predicate function that checks wether a positive integer is arithmetic or not */
arith_nump(n):=block(listify(divisors(n)),apply("+",%%)/length(%%),if integerp(%%) then true)$
 
/* Function that returns a list of the first len arithmetic numbers */
arith_num_count(len):=block(
[i:1,count:0,result:[]],
while count<len do (if arith_nump(i) then (result:endcons(i,result),count:count+1),i:i+1),
result)$
 
/* Test cases */
/* First 100 arithmetic numbers */
arith_num_count(100);
 
/* The 1000th arithmetic number */
last(arith_num_count(1000));
 
/* The 10000th arithmetic number */
last(arith_num_count(10000));
 
/* Number of composites among the first 1000 arithmetic numbers */
block(rest(arith_num_count(1000)),sublist(%%,lambda([x],primep(x)=false)),length(%%));
 
/* Number of composites among the first 10000 arithmetic numbers */
block(rest(arith_num_count(10000)),sublist(%%,lambda([x],primep(x)=false)),length(%%));
</syntaxhighlight>
{{out}}
<pre>
[1,3,5,6,7,11,13,14,15,17,19,20,21,22,23,27,29,30,31,33,35,37,38,39,41,42,43,44,45,46,47,49,51,53,54,55,56,57,59,60,61,62,65,66,67,68,69,70,71,73,77,78,79,83,85,86,87,89,91,92,93,94,95,96,97,99,101,102,103,105,107,109,110,111,113,114,115,116,118,119,123,125,126,127,129,131,132,133,134,135,137,138,139,140,141,142,143,145,147,149]
 
1361
 
12953
 
782
 
8458
</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE ArithmeticNumbers;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
 
CONST
Max = 13000;
 
VAR
divSum: ARRAY [1..Max] OF CARDINAL;
divCount: ARRAY [1..Max] OF CHAR;
current, count, composites: CARDINAL;
 
PROCEDURE CalculateDivisorSums;
VAR div, num: CARDINAL;
BEGIN
FOR num := 1 TO Max DO
divSum[num] := 0;
divCount[num] := CHR(0)
END;
 
FOR div := 1 TO Max DO
num := div;
WHILE num <= Max DO
INC(divSum[num], div);
INC(divCount[num]);
INC(num, div)
END
END
END CalculateDivisorSums;
 
PROCEDURE Next(n: CARDINAL): CARDINAL;
BEGIN
REPEAT INC(n) UNTIL (divSum[n] MOD ORD(divCount[n])) = 0;
RETURN n
END Next;
 
PROCEDURE Composite(n: CARDINAL): BOOLEAN;
BEGIN
RETURN (n>1) AND (divSum[n] # n+1)
END Composite;
 
BEGIN
CalculateDivisorSums;
WriteString("First 100 arithmetic numbers:");
WriteLn;
 
current := 0;
FOR count := 1 TO 10000 DO
current := Next(current);
IF Composite(current) THEN INC(composites) END;
IF count <= 100 THEN
WriteCard(current, 5);
IF count MOD 10 = 0 THEN WriteLn END
END;
 
IF (count = 1000) OR (count = 10000) THEN
WriteCard(count, 5);
WriteString(": ");
WriteCard(current, 5);
WriteString(", ");
WriteCard(composites, 5);
WriteString(" composites");
WriteLn
END;
END
END ArithmeticNumbers.</syntaxhighlight>
{{out}}
<pre>First 100 arithmetic numbers:
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
1000: 1361, 782 composites
10000: 12953, 8458 composites</pre>
=={{header|Nim}}==
<syntaxhighlight lang="Nim">import std/strformat
Line 2,920 ⟶ 3,380:
Number of composite arithmetic numbers <= 1228663: 905043
</pre>
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
object ArithmeticNumbers extends App {
var arithmeticCount = 0
var compositeCount = 0
var n = 1
 
while (arithmeticCount <= 1_000_000) {
val factors = findFactors(n)
val sum = factors.sum
if (sum % factors.size == 0) {
arithmeticCount += 1
if (factors.size > 2) compositeCount += 1
if (arithmeticCount <= 100) {
print(f"$n%3d" + (if (arithmeticCount % 10 == 0) "\n" else " "))
}
if (List(1_000, 10_000, 100_000, 1_000_000).contains(arithmeticCount)) {
println()
println(s"${arithmeticCount}th arithmetic number is $n")
println(s"Number of composite arithmetic numbers <= $n: $compositeCount")
}
}
n += 1
}
 
def findFactors(number: Int): Set[Int] = {
(1 to number).filter(number % _ == 0).toSet
}
}
</syntaxhighlight>
{{out}}
<pre>
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
 
1000th arithmetic number is 1361
Number of composite arithmetic numbers <= 1361: 782
 
10000th arithmetic number is 12953
Number of composite arithmetic numbers <= 12953: 8458
 
100000th arithmetic number is 125587
Number of composite arithmetic numbers <= 125587: 88219
 
1000000th arithmetic number is 1228663
Number of composite arithmetic numbers <= 1228663: 905043
 
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program arithmetic_numbers;
[divsum, divcount] := calcdivsums(130000);
 
print("First 100 arithmetic numbers:");
 
loop for nth in [1..100000] do
loop until divsum(num) mod divcount(num) = 0 do num +:= 1; end loop;
comp +:= if num>1 and divsum(num) /= num+1 then 1 else 0 end if;
 
if nth <= 100 then
putchar(rpad(str num, 5));
if nth mod 10 = 0 then print(); end if;
end if;
 
if nth in [1000, 10000, 100000] then
print("The " + nth + "th arithmetic number is " + num + ".");
print("Of the first " + nth + " arithmetic numbers, " +
comp + " are composite.");
end if;
end loop;
 
proc calcdivsums(m);
sums := [];
counts := [];
loop for d in [1..m] do
loop for n in [d, d*2..m] do
sums(n) +:= d;
counts(n) +:= 1;
end loop;
end loop;
return [sums, counts];
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>First 100 arithmetic numbers:
1 3 5 6 7 11 13 14 15 17
19 20 21 22 23 27 29 30 31 33
35 37 38 39 41 42 43 44 45 46
47 49 51 53 54 55 56 57 59 60
61 62 65 66 67 68 69 70 71 73
77 78 79 83 85 86 87 89 91 92
93 94 95 96 97 99 101 102 103 105
107 109 110 111 113 114 115 116 118 119
123 125 126 127 129 131 132 133 134 135
137 138 139 140 141 142 143 145 147 149
The 1000th arithmetic number is 1361.
Of the first 1000 arithmetic numbers, 782 are composite.
The 10000th arithmetic number is 12953.
Of the first 10000 arithmetic numbers, 8458 are composite.
The 100000th arithmetic number is 125587.
Of the first 100000 arithmetic numbers, 88219 are composite.</pre>
 
=={{header|VBScript}}==
Line 2,993 ⟶ 3,564:
</pre>
</small>
 
 
=={{header|Wren}}==
Line 2,999 ⟶ 3,569:
{{libheader|Wren-fmt}}
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./fmt" for Fmt
import "./sort" for Find
2,114

edits