Jump to content

Arithmetic numbers: Difference between revisions

Added Oberon-07
(Add Modula-2)
(Added Oberon-07)
 
Line 2,480:
1000000th arithmetic number: 1228663
Number of composite arithmetic numbers ⩽ 1228663: 905043
</pre>
 
=={{header|Oberon-07}}==
{{Trans|Modula-2}}
<syntaxhighlight lang="modula2">
MODULE ArithmeticNumbers;
IMPORT Out;
 
CONST
Max = 130000;
 
VAR divSum: ARRAY Max + 1 OF INTEGER;
divCount: ARRAY Max + 1 OF CHAR;
current, count, composites: INTEGER;
 
PROCEDURE CalculateDivisorSums;
VAR div, num: INTEGER;
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
divSum[num] := divSum[num] + div;
divCount[num] := CHR(ORD(divCount[num]) + 1);
num := num + div
END
END
END CalculateDivisorSums;
 
PROCEDURE Next(n: INTEGER): INTEGER;
BEGIN
REPEAT n := n + 1 UNTIL (divSum[n] MOD ORD(divCount[n])) = 0;
RETURN n
END Next;
 
PROCEDURE Composite(n: INTEGER): BOOLEAN;
BEGIN
RETURN (n>1) & (divSum[n] # n+1)
END Composite;
 
BEGIN
CalculateDivisorSums;
Out.String("First 100 arithmetic numbers:");
Out.Ln;
 
current := 0;
FOR count := 1 TO 100000 DO
current := Next(current);
IF Composite(current) THEN composites := composites + 1 END;
IF count <= 100 THEN
Out.Int(current, 5);
IF count MOD 10 = 0 THEN Out.Ln END
END;
 
IF (count = 1000) OR (count = 10000) OR (count = 100000) THEN
Out.Int(count, 6);
Out.String("th: ");
Out.Int(current, 6);
Out.String(", ");
Out.Int(composites, 6);
Out.String(" composites");
Out.Ln
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
1000th: 1361, 782 composites
10000th: 12953, 8458 composites
100000th: 125587, 88219 composites
</pre>
 
3,043

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.