Abundant odd numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎{{header|Go}}: Updated in line with revised task requirements.)
(→‎{{header|REXX}}: revised program to deal with new task requirements.)
Line 200: Line 200:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX pgm displays N nice numbers, where nice #'s are whose sum of its factors > #. */
<lang rexx>/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandth, first > 1 billion. */
parse arg N . /*obtain optional arguments from the CL*/
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N= 25 /*Not specified? Then use the default.*/
if Nlow=='' | Nlow=="," then Nlow= 25 /*Not specified? Then use the default.*/
w= length(N); ww= w+ w /*used for aligning the columnar output*/
if Nuno=='' | Nuno=="," then Nuno= 1000 /* " " " " " " */
# = 0 /*count of nice numbers (so far). */
if Novr=='' | Novr=="," then Novr= 1000000000 /* " " " " " " */
numeric digits max(9, length(Novr) ) /*ensure enough decimal digits for // */
do j=1 until #>=N; $=sigma(j) /*get sigma for an integer. */
if $<=j then iterate /*sigma + J ? Then ignore it. */
@= 'odd abundant number' /*variable for annotating the output. */
# = 0 /*count of odd abundant numbers so far.*/
#= # + 1
say 'nice number ' right(#,w) " is:" right(j,ww)', sigma is:' right($,ww)
do j=5 by 10 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 th(#) @ 'is: ' commas(j) right('sigma=',20) commas($)
end /*j*/
say
# = 0 /*count of odd abundant numbers so far.*/
do j=5 by 10; $= 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 #<Nuno then iterate /*Odd abundant# count<Nuno? Then skip.*/
say th(#) @ 'is: ' commas(j) right('sigma=',20) commas($)
leave
end /*j*/
say
do j=5+Novr%5*5 by 10; $= sigO(j) /*get sigma for an odd integer > Novr. */
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
say th(1) @ 'over' commas(Novr) "is: " commas(j) right('sigma=',20) commas($)
leave
end /*j*/
end /*j*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sigma: procedure; parse arg x; if x<2 then return 0; odd= x // 2 /* // ◄──remainder.*/
commas:parse arg _; do c_=length(_)-3 to 1 by -3; _=insert(',', _, c_); end; return _
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
s= 1 /* [↓] only use EVEN or ODD integers.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
do j=2+odd by 1+odd while j*j<x /*divide by all integers up to √x. */
if x//j==0 then s= s + j + x%j /*add the two divisors to (sigma) sum. */
sigO: procedure; parse arg x; s= 1 /*sigma for odd integers. ___*/
end /*j*/ /* [↑] % is the REXX integer division*/
do k=3 by 2 while k*k<x /*divide by all odd integers up to x */
/* [↓] adjust for a square. ___ */
if x//k==0 then s= s + k + x%k /*add the two divisors to (sigma) sum. */
if j*j==x then return s + j /*Was X a square? If so, add x */
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. */</lang>
return s /*return (sigma) sum of the divisors. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
nice number 1 is: 12, sigma is: 16
1st odd abundant number is: 945 sigma= 975
nice number 2 is: 18, sigma is: 21
2nd odd abundant number is: 1,575 sigma= 1,649
nice number 3 is: 20, sigma is: 22
3rd odd abundant number is: 2,205 sigma= 2,241
nice number 4 is: 24, sigma is: 36
4th odd abundant number is: 2,835 sigma= 2,973
nice number 5 is: 30, sigma is: 42
5th odd abundant number is: 3,465 sigma= 4,023
nice number 6 is: 36, sigma is: 55
6th odd abundant number is: 4,095 sigma= 4,641
nice number 7 is: 40, sigma is: 50
7th odd abundant number is: 4,725 sigma= 5,195
nice number 8 is: 42, sigma is: 54
8th odd abundant number is: 5,355 sigma= 5,877
nice number 9 is: 48, sigma is: 76
9th odd abundant number is: 5,775 sigma= 6,129
nice number 10 is: 54, sigma is: 66
10th odd abundant number is: 5,985 sigma= 6,495
nice number 11 is: 56, sigma is: 64
11th odd abundant number is: 6,435 sigma= 6,669
nice number 12 is: 60, sigma is: 108
12th odd abundant number is: 6,615 sigma= 7,065
nice number 13 is: 66, sigma is: 78
13th odd abundant number is: 6,825 sigma= 7,063
nice number 14 is: 70, sigma is: 74
14th odd abundant number is: 7,245 sigma= 7,731
nice number 15 is: 72, sigma is: 123
15th odd abundant number is: 7,425 sigma= 7,455
nice number 16 is: 78, sigma is: 90
16th odd abundant number is: 7,875 sigma= 8,349
nice number 17 is: 80, sigma is: 106
17th odd abundant number is: 8,085 sigma= 8,331
nice number 18 is: 84, sigma is: 140
18th odd abundant number is: 8,415 sigma= 8,433
nice number 19 is: 88, sigma is: 92
19th odd abundant number is: 8,505 sigma= 8,967
nice number 20 is: 90, sigma is: 144
20th odd abundant number is: 8,925 sigma= 8,931
nice number 21 is: 96, sigma is: 156
21st odd abundant number is: 9,135 sigma= 9,585
nice number 22 is: 100, sigma is: 117
22nd odd abundant number is: 9,555 sigma= 9,597
nice number 23 is: 102, sigma is: 114
23rd odd abundant number is: 9,765 sigma= 10,203
nice number 24 is: 104, sigma is: 106
24th odd abundant number is: 10,395 sigma= 12,645
nice number 25 is: 108, sigma is: 172
25th odd abundant number is: 11,025 sigma= 11,946

1000th odd abundant number is: 498,225 sigma= 529,487

1st odd abundant number over 1,000,000,000 is: 1,000,000,575 sigma= 1,083,561,009
</pre>
</pre>



Revision as of 22:04, 17 May 2019

Abundant odd numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

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 / 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.


Task name and requirements requirements have changed, (and may change again) see discussion page for details.

Go

<lang go>package main

import (

   "fmt"
   "strconv"

)

func divisors(n int) []int {

   divs := []int{1}
   divs2 := []int{}
   for i := 2; i*i <= n; i++ {
       if n%i == 0 {
           j := n / i
           divs = append(divs, i)
           if i != j {
               divs2 = append(divs2, j)
           }
       }
   }
   for i := len(divs2) - 1; i >= 0; i-- {
       divs = append(divs, divs2[i])
   }
   return divs

}

func sum(divs []int) int {

   tot := 0
   for _, div := range divs {
       tot += div
   }
   return tot

}

func sumStr(divs []int) string {

   s := ""
   for _, div := range divs {
       s += strconv.Itoa(div) + " + "
   }
   return s[0 : len(s)-3]

}

func main() {

   const max = 25
   fmt.Println("The first", max, "abundant odd numbers are:")
   count := 0
   var n int
   for n = 1; count < max; n += 2 {
       divs := divisors(n)
       if tot := sum(divs); tot > n {
           count++
           s := sumStr(divs)
           fmt.Printf("%2d. %5d < %s = %d\n", count, n, s, tot)
       }
   }
   fmt.Println("\nThe one thousandth abundant odd number is:")
   for ; ; n += 2 {
       divs := divisors(n)
       if tot := sum(divs); tot > n {
           count++
           if count == 1000 {
               s := sumStr(divs)
               fmt.Printf("%d < %s = %d\n", n, s, tot)
               break
           }
       }
   }
   fmt.Println("\nThe first abundant odd number above one billion is:")
   for n = 1e9 + 1; ; n += 2 {
       divs := divisors(n)
       if tot := sum(divs); tot > n {
           s := sumStr(divs)
           fmt.Printf("%d < %s = %d\n", n, s, tot)
           break
       }
   }

}</lang>

Output:
The first 25 abundant odd numbers are:
 1.   945 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975
 2.  1575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649
 3.  2205 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241
 4.  2835 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973
 5.  3465 < 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155 = 4023
 6.  4095 < 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365 = 4641
 7.  4725 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575 = 5195
 8.  5355 < 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785 = 5877
 9.  5775 < 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925 = 6129
10.  5985 < 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995 = 6495
11.  6435 < 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145 = 6669
12.  6615 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205 = 7065
13.  6825 < 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275 = 7063
14.  7245 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415 = 7731
15.  7425 < 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475 = 7455
16.  7875 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625 = 8349
17.  8085 < 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695 = 8331
18.  8415 < 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805 = 8433
19.  8505 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835 = 8967
20.  8925 < 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975 = 8931
21.  9135 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045 = 9585
22.  9555 < 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185 = 9597
23.  9765 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255 = 10203
24. 10395 < 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 27 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 135 + 165 + 189 + 231 + 297 + 315 + 385 + 495 + 693 + 945 + 1155 + 1485 + 2079 + 3465 = 12645
25. 11025 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 = 11946

The one thousandth abundant odd number is:
492975 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 313 + 315 + 525 + 939 + 1565 + 1575 + 2191 + 2817 + 4695 + 6573 + 7825 + 10955 + 14085 + 19719 + 23475 + 32865 + 54775 + 70425 + 98595 + 164325 = 519361

The first abundant odd number above one billion is:
1000000575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009

Perl 6

Works with: Rakudo version 2019.03

Takes a little over 5 seconds to complete (on my not-very-fast system).

<lang perl6>sub abundant (\x) {

   my @l = x.is-prime ?? 1 !! flat
   1, (2 .. x.sqrt.floor).map: -> \d {
        my \y = x div d;
        next if y * d !== x;
        d !== y ?? (d, y) !! d
   };
   (my $s = @l.sum) > x ?? (@l.sort) !! Empty;

}

sub odd-abundants (Int :$start-at is copy) {

   $start-at = ( $start-at + 14 ) div 15;
   $start-at += $start-at %% 2;
   $start-at *= 15;
   ($start-at, *+30 ... *).hyper.map: {
       next unless my $oa = .&abundant;
       sprintf "%6d: divisor sum: {$oa.join: ' + '} = {$oa.sum}", $_
   }

}

put 'First 25 abundant odd numbers:'; .put for odd-abundants( :start-at(1) )[^25];

put "\nOne thousandth abundant odd number:\n" ~ odd-abundants( :start-at(1) )[999] ~

"\n\nFirst abundant odd number above one billion:\n" ~ odd-abundants( :start-at(1_000_000_000) ).head;</lang>

Output:
First 25 abundant odd numbers:
   945: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975
  1575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649
  2205: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241
  2835: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973
  3465: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155 = 4023
  4095: divisor sum: 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365 = 4641
  4725: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575 = 5195
  5355: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785 = 5877
  5775: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925 = 6129
  5985: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995 = 6495
  6435: divisor sum: 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145 = 6669
  6615: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205 = 7065
  6825: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275 = 7063
  7245: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415 = 7731
  7425: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475 = 7455
  7875: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625 = 8349
  8085: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695 = 8331
  8415: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805 = 8433
  8505: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835 = 8967
  8925: divisor sum: 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975 = 8931
  9135: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045 = 9585
  9555: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185 = 9597
  9765: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255 = 10203
 10395: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 27 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 135 + 165 + 189 + 231 + 297 + 315 + 385 + 495 + 693 + 945 + 1155 + 1485 + 2079 + 3465 = 12645
 11025: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 = 11946

One thousandth abundant odd number:
498225: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 73 + 75 + 91 + 105 + 175 + 195 + 219 + 273 + 325 + 365 + 455 + 511 + 525 + 949 + 975 + 1095 + 1365 + 1533 + 1825 + 2275 + 2555 + 2847 + 4745 + 5475 + 6643 + 6825 + 7665 + 12775 + 14235 + 19929 + 23725 + 33215 + 38325 + 71175 + 99645 + 166075 = 529487

First abundant odd number above one billion:
1000000575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009

REXX

<lang rexx>/*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. */

  1. = 0 /*count of odd abundant numbers so far.*/
     do j=5  by 10  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 th(#)  @   'is: '   commas(j)    right('sigma=',20)    commas($)
     end  /*j*/

say

  1. = 0 /*count of odd abundant numbers so far.*/
     do j=5  by 10;                 $= 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 #<Nuno  then iterate                    /*Odd abundant# count<Nuno?  Then skip.*/
     say th(#)  @   'is: '   commas(j)    right('sigma=',20)    commas($)
     leave
     end  /*j*/

say

     do j=5+Novr%5*5  by 10;        $= sigO(j)  /*get sigma for an odd integer > Novr. */
     if $<=j    then iterate                    /*sigma  ≤  J ?    Then ignore it.     */
     say th(1)  @  'over'  commas(Novr)  "is: "  commas(j)  right('sigma=',20)  commas($)
     leave
     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 _ th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4)) /*──────────────────────────────────────────────────────────────────────────────────────*/ sigO: procedure; parse arg x; s= 1 /*sigma for odd integers. ___*/

            do k=3  by 2  while k*k<x           /*divide by all odd integers up to √ x */
            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.  */</lang>
output   when using the default input:
1st odd abundant number is:  945               sigma= 975
2nd odd abundant number is:  1,575               sigma= 1,649
3rd odd abundant number is:  2,205               sigma= 2,241
4th odd abundant number is:  2,835               sigma= 2,973
5th odd abundant number is:  3,465               sigma= 4,023
6th odd abundant number is:  4,095               sigma= 4,641
7th odd abundant number is:  4,725               sigma= 5,195
8th odd abundant number is:  5,355               sigma= 5,877
9th odd abundant number is:  5,775               sigma= 6,129
10th odd abundant number is:  5,985               sigma= 6,495
11th odd abundant number is:  6,435               sigma= 6,669
12th odd abundant number is:  6,615               sigma= 7,065
13th odd abundant number is:  6,825               sigma= 7,063
14th odd abundant number is:  7,245               sigma= 7,731
15th odd abundant number is:  7,425               sigma= 7,455
16th odd abundant number is:  7,875               sigma= 8,349
17th odd abundant number is:  8,085               sigma= 8,331
18th odd abundant number is:  8,415               sigma= 8,433
19th odd abundant number is:  8,505               sigma= 8,967
20th odd abundant number is:  8,925               sigma= 8,931
21st odd abundant number is:  9,135               sigma= 9,585
22nd odd abundant number is:  9,555               sigma= 9,597
23rd odd abundant number is:  9,765               sigma= 10,203
24th odd abundant number is:  10,395               sigma= 12,645
25th odd abundant number is:  11,025               sigma= 11,946

1000th odd abundant number is:  498,225               sigma= 529,487

1st odd abundant number over 1,000,000,000 is:  1,000,000,575               sigma= 1,083,561,009

Ring

<lang ring>

  1. Project: Nice numbers

max = 25 nr = 0 m = 1 check = 0 index = 0 while true

     nice(m)
     if check = 1
        nr = nr + 1
     ok
     if nr = max
        exit
     ok
     m = m + 1

end

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
       showArray(n,nArray,sum,index)
    ok

func showArray(n,nArray,sum,index)

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

</lang>

Output:
1. 12 => 1 + 2 + 3 + 4 + 6 = 16 > 12
2. 18 => 1 + 2 + 3 + 6 + 9 = 21 > 18
3. 20 => 1 + 2 + 4 + 5 + 10 = 22 > 20
4. 24 => 1 + 2 + 3 + 4 + 6 + 8 + 12 = 36 > 24
5. 30 => 1 + 2 + 3 + 5 + 6 + 10 + 15 = 42 > 30
6. 36 => 1 + 2 + 3 + 4 + 6 + 9 + 12 + 18 = 55 > 36
7. 40 => 1 + 2 + 4 + 5 + 8 + 10 + 20 = 50 > 40
8. 42 => 1 + 2 + 3 + 6 + 7 + 14 + 21 = 54 > 42
9. 48 => 1 + 2 + 3 + 4 + 6 + 8 + 12 + 16 + 24 = 76 > 48
10. 54 => 1 + 2 + 3 + 6 + 9 + 18 + 27 = 66 > 54
11. 56 => 1 + 2 + 4 + 7 + 8 + 14 + 28 = 64 > 56
12. 60 => 1 + 2 + 3 + 4 + 5 + 6 + 10 + 12 + 15 + 20 + 30 = 108 > 60
13. 66 => 1 + 2 + 3 + 6 + 11 + 22 + 33 = 78 > 66
14. 70 => 1 + 2 + 5 + 7 + 10 + 14 + 35 = 74 > 70
15. 72 => 1 + 2 + 3 + 4 + 6 + 8 + 9 + 12 + 18 + 24 + 36 = 123 > 72
16. 78 => 1 + 2 + 3 + 6 + 13 + 26 + 39 = 90 > 78
17. 80 => 1 + 2 + 4 + 5 + 8 + 10 + 16 + 20 + 40 = 106 > 80
18. 84 => 1 + 2 + 3 + 4 + 6 + 7 + 12 + 14 + 21 + 28 + 42 = 140 > 84
19. 88 => 1 + 2 + 4 + 8 + 11 + 22 + 44 = 92 > 88
20. 90 => 1 + 2 + 3 + 5 + 6 + 9 + 10 + 15 + 18 + 30 + 45 = 144 > 90
21. 96 => 1 + 2 + 3 + 4 + 6 + 8 + 12 + 16 + 24 + 32 + 48 = 156 > 96
22. 100 => 1 + 2 + 4 + 5 + 10 + 20 + 25 + 50 = 117 > 100
23. 102 => 1 + 2 + 3 + 6 + 17 + 34 + 51 = 114 > 102
24. 104 => 1 + 2 + 4 + 8 + 13 + 26 + 52 = 106 > 104
25. 108 => 1 + 2 + 3 + 4 + 6 + 9 + 12 + 18 + 27 + 36 + 54 = 172 > 108