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.



E.G.

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.



Task
Find and display here: at least the first 25 abundant odd numbers and either their proper divisor sum or sigma sum.
Find and display here: the one thousandth abundant odd number and either its proper divisor sum or sigma sum.
Find and display here: the first abundant odd number greater than one billion (109) and either its proper divisor sum or sigma sum.


References

   OEIS:A005231: Odd abundant numbers (odd numbers n whose sum of divisors exceeds 2n)
   American Journal of Mathematics, Vol. 35, No. 4 (Oct., 1913), pp. 413-422 - Finiteness of the Odd Perfect and Primitive Abundant Numbers with n Distinct Prime Factors (LE Dickson)


 
from math import sqrt
import strformat
 
#---------------------------------------------------------------------------------------------------
 
proc sumProperDivisors(n: int): int =
  ## Compute the sum of proper divisors.
  ## "n" is supposed to be odd.
  result = 1
  for d in countup(3, sqrt(n.toFloat).int, 2):
    if n mod d == 0:
      inc result, d
      if n div d != d:
        inc result, n div d
 
#---------------------------------------------------------------------------------------------------
 
iterator oddAbundant(start: int): tuple[n, s: int] =
  ## Yield the odd abundant numbers and the sum of their proper
  ## divisors greater or equal to "start".
  var n = start + (start and 1 xor 1)   # Start with an odd number.
  while true:
    let s = n.sumProperDivisors()
    if s > n:
      yield (n, s)
    inc n, 2
 
#---------------------------------------------------------------------------------------------------
 
echo "List of 25 first odd abundant numbers."
echo "Rank  Number  Proper divisors sum"
echo "----  -----   -------------------"
var rank = 0
for (n, s) in oddAbundant(1):
  inc rank
  echo fmt"{rank:2}:   {n:5}   {s:5}"
  if rank == 25:
    break
 
echo ""
rank = 0
for (n, s) in oddAbundant(1):
  inc rank
  if rank == 1000:
    echo fmt"The 1000th odd abundant number is {n}."
    echo fmt"The sum of its proper divisors is {s}."
    break
 
echo ""
for (n, s) in oddAbundant(1_000_000_000):
  if n > 1_000_000_000:
    echo fmt"The first odd abundant number greater than 1000000000 is {n}."
    echo fmt"The sum of its proper divisors is {s}."
    break
 