Erdős-Nicolas numbers: Difference between revisions

Added Algol 68
(Added Algol 68)
Line 23:
* [[oeis:A194472|OEIS:A194472 - Erdős–Nicolas numbers]]
<br><br>
 
=={{header|ALGOL 68}}==
Builds tables of proper divisor counts and sums and finds the numbers whilst doing it. This means that the numbers are not found in numerical order.
<lang algol68>BEGIN # find some Erdos-Nicolas numbers: numbers equal to the sum of their #
# first k proper divisors but k is not the count of all their proper #
# divisors ( so the numbers aren't perfect ) #
INT max number = 2 000 000; # largest number we will consider #
# construct tables of the divisor counts and divisor sums and check for #
# the numbers as we do it - note they will not necessarily be found in #
# order #
[ 1 : max number ]INT dsum; FOR i TO UPB dsum DO dsum[ i ] := 1 OD;
[ 1 : max number ]INT dcount; FOR i TO UPB dcount DO dcount[ i ] := 1 OD;
FOR i FROM 2 TO UPB dsum
DO FOR j FROM i + i BY i TO UPB dsum DO
# have another proper divisor #
IF dsum[ j ] = j THEN
# the divisor sum is currently equal to the number but is #
# about to increase, so we have an Erdos-Nicolas number #
print( ( whole( j, -10 ), " equals the sum of its first "
, whole( dcount[ j ], 0 ), " divisors"
, newline
)
)
FI;
dsum[ j ] +:= i;
dcount[ j ] +:= 1
OD
OD
END</lang>
{{out}}
<pre>
24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
</pre>
 
With max number set to 200 000 000, another two numbers can be found. Note that that would probably be too large for ALGOL 68G under Windows, so another compiler would need to be used:
 
<pre>
24 equals the sum of its first 6 divisors
2016 equals the sum of its first 31 divisors
8190 equals the sum of its first 43 divisors
42336 equals the sum of its first 66 divisors
45864 equals the sum of its first 66 divisors
714240 equals the sum of its first 113 divisors
392448 equals the sum of its first 68 divisors
1571328 equals the sum of its first 115 divisors
61900800 equals the sum of its first 280 divisors
91963648 equals the sum of its first 142 divisors
</pre>
 
=={{header|J}}==
3,021

edits