How to resolve the algorithm Erdős-Nicolas numbers step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Erdős-Nicolas numbers step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

An Erdős–Nicolas number is a positive integer which is not perfect but is equal to the sum of its first k divisors (arranged in ascending order and including one) for some value of k greater than one. 24 is an Erdős–Nicolas number because the sum of its first 6 divisors (1, 2, 3, 4, 6 and 8) is equal to 24 and it is not perfect because 12 is also a divisor. 6 is not an Erdős–Nicolas number because it is perfect (1 + 2 + 3 = 6). 48 is not an Erdős–Nicolas number because its divisors are: 1, 2, 3, 4, 6, 8, 12, 16, 24 and 48. The first seven of these add up to 36, but the first eight add up to 52 which is more than 48. Find and show here the first 8 Erdős–Nicolas numbers and the number of divisors needed (i.e. the value of 'k') to satisfy the definition. Do the same for any further Erdős–Nicolas numbers which you have the patience for. As all known Erdős–Nicolas numbers are even you may assume this to be generally true in order to quicken up the search. However, it is not obvious (to me at least) why this should necessarily be the case.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Erdős-Nicolas numbers step by step in the ALGOL 68 programming language

Source code in the algol programming language

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

  

You may also check:How to resolve the algorithm Check output device is a terminal step by step in the Lua programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Scilab programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Swift programming language
You may also check:How to resolve the algorithm Delegates step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Handle a signal step by step in the Wren programming language