How to resolve the algorithm Abundant odd numbers step by step in the Ring programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Abundant odd numbers step by step in the Ring programming language

Table of Contents

Problem Statement

An Abundant number is a number n for which the   sum of divisors   σ(n) > 2n, or,   equivalently,   the   sum of proper divisors   (or aliquot sum)       s(n) > n.

12   is abundant, it has the proper divisors     1,2,3,4 & 6     which sum to   16   ( > 12 or n);        or alternately,   has the sigma sum of   1,2,3,4,6 & 12   which sum to   28   ( > 24 or 2n).

Abundant numbers are common, though even abundant numbers seem to be much more common than odd abundant numbers. To make things more interesting, this task is specifically about finding   odd abundant numbers.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Abundant odd numbers step by step in the Ring programming language

Source code in the ring programming language

#Project: Anbundant odd numbers

max = 100000000
limit = 25
nr = 0
m = 1
check = 0
index = 0
see "working..." + nl
see "wait for done..." + nl
while true
      check = 0
      if m%2 = 1
         nice(m)
      ok
      if check = 1
         nr = nr + 1
      ok
      if nr = max
         exit
      ok
      m = m + 1
end
see "done..." + nl

func nice(n)
     check = 0
     nArray = []
     for i = 1 to n - 1
         if n % i = 0
            add(nArray,i)
         ok
     next
     sum = 0
     for p = 1 to len(nArray)
         sum = sum + nArray[p]
     next
     if sum > n
        check = 1
        index = index + 1
        if index < limit + 1
           showArray(n,nArray,sum,index)
        ok
        if index = 100
           see "One thousandth abundant odd number:" + nl
           showArray2(n,nArray,sum,index)
        ok
        if index = 100000000
           see "First abundant odd number above one billion:" + nl
           showArray2(n,nArray,sum,index)
        ok
     ok

func showArray(n,nArray,sum,index)
        see "" + index + ". " + string(n) + ": divisor sum: " 
        for m = 1 to len(nArray)
            if m < len(nArray)
               see string(nArray[m]) + " + "
            else
               see string(nArray[m]) + " = " + string(sum) + nl + nl
            ok
        next

func showArray2(n,nArray,sum,index)
        see "" + index + ". " + string(n) + ": divisor sum: " + 
        see string(nArray[m]) + " = " + string(sum) + nl + nl

  

You may also check:How to resolve the algorithm XML/Input step by step in the PHP programming language
You may also check:How to resolve the algorithm Duffinian numbers step by step in the Ruby programming language
You may also check:How to resolve the algorithm Loops/Increment loop index within loop body step by step in the REXX programming language
You may also check:How to resolve the algorithm Metered concurrency step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm 100 doors step by step in the ColdFusion programming language