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

Published on 12 May 2024 09:40 PM

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

Source code in the ring programming language

see "works..." + nl
erdos = []
limit = 1600000
for n = 1 to limit
    num = 0
    sum = 0
    erdos = []
    for m = 1 to n/2
        if n%m = 0
           add(erdos,m)
        ok
    next
    lenErdos = len(erdos)
    for p = 1 to lenErdos 
        sum = sum + erdos[p]
        if sum = n and p < lenErdos 
           num++
           see "" + n + " equals the sum of its first " + p + " divisors" + nl
           exit
        ok
    next
    if num = 8
       exit
    ok
next
see "done..." + nl

  

You may also check:How to resolve the algorithm SHA-1 step by step in the Scala programming language
You may also check:How to resolve the algorithm Empty directory step by step in the J programming language
You may also check:How to resolve the algorithm Averages/Mean time of day step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm UTF-8 encode and decode step by step in the jq programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the ALGOL 68 programming language