Arithmetic numbers: Difference between revisions

Add Draco
imported>Maxima enthusiast
(Add Draco)
Line 1,333:
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,444:
.
</syntaxhighlight>
 
 
=={{header|FutureBasic}}==
2,114

edits