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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Abundant odd numbers step by step in the REXX 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 REXX programming language

Source code in the rexx programming language

/*REXX pgm displays abundant odd numbers:  1st 25,  one─thousandth,  first > 1 billion. */
parse arg Nlow Nuno Novr .                       /*obtain optional arguments from the CL*/
if Nlow=='' | Nlow==","  then Nlow=          25  /*Not specified?  Then use the default.*/
if Nuno=='' | Nuno==","  then Nuno=        1000  /* "      "         "   "   "     "    */
if Novr=='' | Novr==","  then Novr=  1000000000  /* "      "         "   "   "     "    */
numeric digits max(9, length(Novr) )             /*ensure enough decimal digits for  // */
@= 'odd abundant number'                         /*variable for annotating the output.  */
#= 0                                             /*count of odd abundant numbers so far.*/
      do j=3  by 2  until #>=Nlow;   $= sigO(j)  /*get the  sigma  for an odd integer.  */
      if $<=j  then iterate                      /*sigma  ≤  J ?    Then ignore it.     */
      #= # + 1                                   /*bump the counter for abundant odd #'s*/
      say rt(th(#))     @      'is:'rt(commas(j), 8)     rt("sigma=")     rt(commas($), 9)
      end  /*j*/
say
#= 0                                             /*count of odd abundant numbers so far.*/
      do j=3  by 2;                  $= sigO(j)  /*get the  sigma  for an odd integer.  */
      if $<=j    then iterate                    /*sigma  ≤  J ?    Then ignore it.     */
      #= # + 1                                   /*bump the counter for abundant odd #'s*/
      if #
      say rt(th(#))     @      'is:'rt(commas(j), 8)     rt("sigma=")     rt(commas($), 9)
      leave                                      /*we're finished displaying NUNOth num.*/
      end  /*j*/
say
      do j=1+Novr%2*2  by 2;         $= sigO(j)  /*get sigma for an odd integer > Novr. */
      if $<=j    then iterate                    /*sigma  ≤  J ?    Then ignore it.     */
      say rt(th(1))   @  'over'  commas(Novr)  "is: "   commas(j)  rt('sigma=')  commas($)
      leave                                      /*we're finished displaying NOVRth num.*/
      end  /*j*/
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas:parse arg _;  do c_=length(_)-3  to 1  by -3; _=insert(',', _, c_);  end;  return _
rt:    procedure;  parse arg #,len;     if len==''  then len= 20;     return right(#, len)
th:    parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigO:  parse arg x;            s= 1              /*sigma for odd integers.           ___*/
             do k=3  by 2  while k*k
             if x//k==0  then  s= s + k + x%k    /*add the two divisors to (sigma) sum. */
             end   /*k*/                         /*                                  ___*/
       if k*k==x  then  return s + k             /*Was  X  a square?    If so, add  √ x */
                        return s                 /*return (sigma) sum of the divisors.  */


  

You may also check:How to resolve the algorithm Environment variables step by step in the Nim programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Racket programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Tiny BASIC programming language
You may also check:How to resolve the algorithm Date format step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Special characters step by step in the AWK programming language