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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Erdős-Nicolas numbers step by step in the XPL0 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 XPL0 programming language

Source code in the xpl0 programming language

def Max = 2_000_000;
int DSum(Max+1), DCount(Max+1);
int I, J;
[for I:= 0 to Max do
    [DSum(I):= 1;
    DCount(I):= 1;
    ];
Format(8, 0);
for I:= 2 to Max do
    [J:= I+I;
    while J <= Max do
        [if DSum(J) = J then
            [RlOut(0, float(J));
            Text(0, " equals the sum of its first ");
            IntOut(0, DCount(J));
            Text(0, " divisors^j^m");
            ];
        DSum(J):= DSum(J)+I;
        DCount(J):= DCount(J)+1;
        J:= J+I;
        ]
    ]
]

  

You may also check:How to resolve the algorithm Mutual recursion step by step in the Factor programming language
You may also check:How to resolve the algorithm Monads/Maybe monad step by step in the Swift programming language
You may also check:How to resolve the algorithm Canonicalize CIDR step by step in the jq programming language
You may also check:How to resolve the algorithm Erdős-Nicolas numbers step by step in the C++ programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the Locomotive Basic programming language