Abundant, deficient and perfect number classifications: Difference between revisions
Content added Content deleted
m (correction comments) |
Not a robot (talk | contribs) (Add Draco) |
||
Line 2,064: | Line 2,064: | ||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
See [[#Pascal]]. |
See [[#Pascal]]. |
||
=={{header|Draco}}== |
|||
<lang draco>/* Fill a given array such that for each N, |
|||
* P[n] is the sum of proper divisors of N */ |
|||
proc nonrec propdivs([*] word p) void: |
|||
word i, j, max; |
|||
max := dim(p,1)-1; |
|||
for i from 0 upto max do p[i] := 0 od; |
|||
for i from 1 upto max/2 do |
|||
for j from i*2 by i upto max do |
|||
p[j] := p[j] + i |
|||
od |
|||
od |
|||
corp |
|||
proc nonrec main() void: |
|||
word MAX = 20000; |
|||
word def, per, ab, i; |
|||
/* Find all required proper divisor sums */ |
|||
[MAX+1] word p; |
|||
propdivs(p); |
|||
def := 0; |
|||
per := 0; |
|||
ab := 0; |
|||
/* Check each number */ |
|||
for i from 1 upto MAX do |
|||
if p[i]<i then def := def + 1 |
|||
elif p[i]=i then per := per + 1 |
|||
elif p[i]>i then ab := ab + 1 |
|||
fi |
|||
od; |
|||
writeln("Deficient: ", def:5); |
|||
writeln("Perfect: ", per:5); |
|||
writeln("Abundant: ", ab:5) |
|||
corp</lang> |
|||
{{out}} |
|||
<pre>Deficient: 15043 |
|||
Perfect: 4 |
|||
Abundant: 4953</pre> |
|||
=={{header|Dyalect}}== |
=={{header|Dyalect}}== |
||