Abundant odd numbers

From Rosetta Code
Task
Abundant odd numbers
You are encouraged to solve this task according to the task description, using any language you may know.

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.


Reference

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)

Ada[edit]

This solution uses the package Generic_Divisors from the Proper Divisors task [[1]].

with Ada.Text_IO, Generic_Divisors;
 
procedure Odd_Abundant is
function Same(P: Positive) return Positive is (P);
 
package Divisor_Sum is new Generic_Divisors
(Result_Type => Natural, None => 0, One => Same, Add => "+");
 
function Abundant(N: Positive) return Boolean is
(Divisor_Sum.Process(N) > N);
 
package NIO is new Ada.Text_IO.Integer_IO(Natural);
 
Current: Positive := 1;
 
procedure Print_Abundant_Line
(Idx: Positive; N: Positive; With_Idx: Boolean:= True) is
begin
if With_Idx then
NIO.Put(Idx, 6); Ada.Text_IO.Put(" |");
else
Ada.Text_IO.Put(" *** |");
end if;
NIO.Put(N, 12); Ada.Text_IO.Put(" | ");
NIO.Put(Divisor_Sum.Process(N), 12); Ada.Text_IO.New_Line;
end Print_Abundant_Line;
 
begin
-- the first 25 abundant odd numbers
Ada.Text_IO.Put_Line(" index | number | proper divisor sum ");
Ada.Text_IO.Put_Line("-------+-------------+--------------------");
for I in 1 .. 25 loop
while not Abundant(Current) loop
Current := Current + 2;
end loop;
Print_Abundant_Line(I, Current);
Current := Current + 2;
end loop;
 
-- the one thousandth abundant odd number
Ada.Text_IO.Put_Line("-------+-------------+--------------------");
for I in 26 .. 1_000 loop
Current := Current + 2;
while not Abundant(Current) loop
Current := Current + 2;
end loop;
end loop;
Print_Abundant_Line(1000, Current);
 
-- the first abundant odd number greater than 10**9
Ada.Text_IO.Put_Line("-------+-------------+--------------------");
Current := 10**9+1;
while not Abundant(Current) loop
Current := Current + 2;
end loop;
Print_Abundant_Line(1, Current, False);
end Odd_Abundant;
Output:
 Index |      Number | proper divisor sum 
-------+-------------+--------------------
     1 |         945 |          975
     2 |        1575 |         1649
     3 |        2205 |         2241
     4 |        2835 |         2973
     5 |        3465 |         4023
     6 |        4095 |         4641
     7 |        4725 |         5195
     8 |        5355 |         5877
     9 |        5775 |         6129
    10 |        5985 |         6495
    11 |        6435 |         6669
    12 |        6615 |         7065
    13 |        6825 |         7063
    14 |        7245 |         7731
    15 |        7425 |         7455
    16 |        7875 |         8349
    17 |        8085 |         8331
    18 |        8415 |         8433
    19 |        8505 |         8967
    20 |        8925 |         8931
    21 |        9135 |         9585
    22 |        9555 |         9597
    23 |        9765 |        10203
    24 |       10395 |        12645
    25 |       11025 |        11946
-------+-------------+--------------------
  1000 |      492975 |       519361
-------+-------------+--------------------
   *** |  1000000575 |   1083561009

ALGOL 68[edit]

BEGIN
# find some abundant odd numbers - numbers where the sum of the proper #
# divisors is bigger than the number #
# itself #
 
# returns the sum of the proper divisors of n #
PROC divisor sum = ( INT n )INT:
BEGIN
INT sum := 1;
FOR d FROM 2 TO ENTIER sqrt( n ) DO
IF n MOD d = 0 THEN
sum +:= d;
IF INT other d := n OVER d;
other d /= d
THEN
sum +:= other d
FI
FI
OD;
sum
END # divisor sum # ;
# find numbers required by the task #
BEGIN
# first 25 odd abundant numbers #
INT odd number := 1;
INT a count := 0;
INT d sum := 0;
print( ( "The first 25 abundant odd numbers:", newline ) );
WHILE a count < 25 DO
IF ( d sum := divisor sum( odd number ) ) > odd number THEN
a count +:= 1;
print( ( whole( odd number, -6 )
, " proper divisor sum: "
, whole( d sum, 0 )
, newline
)
)
FI;
odd number +:= 2
OD;
# 1000th odd abundant number #
WHILE a count < 1 000 DO
IF ( d sum := divisor sum( odd number ) ) > odd number THEN
a count := a count + 1
FI;
odd number +:= 2
OD;
print( ( "1000th abundant odd number:"
, newline
, " "
, whole( odd number - 2, 0 )
, " proper divisor sum: "
, whole( d sum, 0 )
, newline
)
);
# first odd abundant number > one billion #
odd number := 1 000 000 001;
BOOL found := FALSE;
WHILE NOT found DO
IF ( d sum := divisor sum( odd number ) ) > odd number THEN
found := TRUE;
print( ( "First abundant odd number > 1 000 000 000:"
, newline
, " "
, whole( odd number, 0 )
, " proper divisor sum: "
, whole( d sum, 0 )
, newline
)
)
FI;
odd number +:= 2
OD
END
END
Output:
The first 25 abundant odd numbers:
   945 proper divisor sum: 975
  1575 proper divisor sum: 1649
  2205 proper divisor sum: 2241
  2835 proper divisor sum: 2973
  3465 proper divisor sum: 4023
  4095 proper divisor sum: 4641
  4725 proper divisor sum: 5195
  5355 proper divisor sum: 5877
  5775 proper divisor sum: 6129
  5985 proper divisor sum: 6495
  6435 proper divisor sum: 6669
  6615 proper divisor sum: 7065
  6825 proper divisor sum: 7063
  7245 proper divisor sum: 7731
  7425 proper divisor sum: 7455
  7875 proper divisor sum: 8349
  8085 proper divisor sum: 8331
  8415 proper divisor sum: 8433
  8505 proper divisor sum: 8967
  8925 proper divisor sum: 8931
  9135 proper divisor sum: 9585
  9555 proper divisor sum: 9597
  9765 proper divisor sum: 10203
 10395 proper divisor sum: 12645
 11025 proper divisor sum: 11946
1000th abundant odd number:
    492975 proper divisor sum: 519361
First abundant odd number > 1 000 000 000:
    1000000575 proper divisor sum: 1083561009

BASIC256[edit]

Translation of: Visual Basic .NET
 
numimpar = 1
contar = 0
sumaDiv = 0
 
function SumaDivisores(n)
# Devuelve la suma de los divisores propios de n
suma = 1
i = int(sqr(n))
 
for d = 2 to i
if n % d = 0 then
suma += d
otroD = n \ d
if otroD <> d Then suma += otroD
end if
Next d
Return suma
End Function
 
# Encontrar los números requeridos por la tarea:
 
# primeros 25 números abundantes impares
Print "Los primeros 25 números impares abundantes:"
While contar < 25
sumaDiv = SumaDivisores(numimpar)
If sumaDiv > numimpar Then
contar += 1
Print numimpar & " suma divisoria adecuada: " & sumaDiv
End If
numimpar += 2
End While
 
# 1000er número impar abundante
While contar < 1000
sumaDiv = SumaDivisores(numimpar)
print sumaDiv & " " & contar
If sumaDiv > numimpar Then contar += 1
numimpar += 2
End While
Print Chr(10) & "1000º número impar abundante:"
Print " " & (numimpar - 2) & " suma divisoria adecuada: " & sumaDiv
 
# primer número impar abundante > mil millones (millardo)
numimpar = 1000000001
encontrado = False
While Not encontrado
sumaDiv = SumaDivisores(numimpar)
If sumaDiv > numimpar Then
encontrado = True
Print Chr(10) & "Primer número impar abundante > 1 000 000 000:"
Print " " & numimpar & " suma divisoria adecuada: " & sumaDiv
End If
numimpar += 2
End While
End
 


C[edit]

#include <stdio.h>
#include <math.h>
 
// The following function is for odd numbers ONLY
// Please use "for (unsigned i = 2, j; i*i <= n; i ++)" for even and odd numbers
unsigned sum_proper_divisors(const unsigned n) {
unsigned sum = 1;
for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
return sum;
}
 
int main(int argc, char const *argv[]) {
unsigned n, c;
for (n = 1, c = 0; c < 25; n += 2) if (n < sum_proper_divisors(n)) printf("%u: %u\n", ++c, n);
 
for ( ; c < 1000; n += 2) if (n < sum_proper_divisors(n)) c ++;
printf("\nThe one thousandth abundant odd number is: %u\n", n);
 
for (n = 1000000001 ;; n += 2) if (n < sum_proper_divisors(n)) break;
printf("The first abundant odd number above one billion is: %u\n", n);
 
return 0;
}
Output:
1: 945
2: 1575
3: 2205
4: 2835
5: 3465
6: 4095
7: 4725
8: 5355
9: 5775
10: 5985
11: 6435
12: 6615
13: 6825
14: 7245
15: 7425
16: 7875
17: 8085
18: 8415
19: 8505
20: 8925
21: 9135
22: 9555
23: 9765
24: 10395
25: 11025

The one thousandth abundant odd number is: 492977
The first abundant odd number above one billion is: 1000000575


C++[edit]

Translation of: Go
#include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
 
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
 
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
if (i != j) {
divs2.push_back(j);
}
}
}
std::copy(divs2.crbegin(), divs2.crend(), std::back_inserter(divs));
 
return divs;
}
 
int sum(const std::vector<int>& divs) {
return std::accumulate(divs.cbegin(), divs.cend(), 0);
}
 
std::string sumStr(const std::vector<int>& divs) {
auto it = divs.cbegin();
auto end = divs.cend();
std::stringstream ss;
 
if (it != end) {
ss << *it;
it = std::next(it);
}
while (it != end) {
ss << " + " << *it;
it = std::next(it);
}
 
return ss.str();
}
 
int abundantOdd(int searchFrom, int countFrom, int countTo, bool printOne) {
int count = countFrom;
int n = searchFrom;
for (; count < countTo; n += 2) {
auto divs = divisors(n);
int tot = sum(divs);
if (tot > n) {
count++;
if (printOne && count < countTo) {
continue;
}
auto s = sumStr(divs);
if (printOne) {
printf("%d < %s = %d\n", n, s.c_str(), tot);
} else {
printf("%2d. %5d < %s = %d\n", count, n, s.c_str(), tot);
}
}
}
return n;
}
 
int main() {
using namespace std;
 
const int max = 25;
cout << "The first " << max << " abundant odd numbers are:\n";
int n = abundantOdd(1, 0, 25, false);
 
cout << "\nThe one thousandth abundant odd number is:\n";
abundantOdd(n, 25, 1000, true);
 
cout << "\nThe first abundant odd number above one billion is:\n";
abundantOdd(1e9 + 1, 0, 1, true);
 
return 0;
}
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

C#[edit]

using static System.Console;
using System.Collections.Generic;
using System.Linq;
 
public static class AbundantOddNumbers
{
public static void Main() {
WriteLine("First 25 abundant odd numbers:");
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine();
WriteLine($"The 1000th abundant odd number: {AbundantNumbers().ElementAt(999).Format()}");
WriteLine();
WriteLine($"First abundant odd number > 1b: {AbundantNumbers(1_000_000_001).First().Format()}");
}
 
static IEnumerable<(int n, int sum)> AbundantNumbers(int start = 3) =>
start.UpBy(2).Select(n => (n, sum: n.DivisorSum())).Where(x => x.sum > x.n);
 
static int DivisorSum(this int n) => 3.UpBy(2).TakeWhile(i => i * i <= n).Where(i => n % i == 0)
.Select(i => (a:i, b:n/i)).Sum(p => p.a == p.b ? p.a : p.a + p.b) + 1;
 
static IEnumerable<int> UpBy(this int n, int step) {
for (int i = n; ; i+=step) yield return i;
}
 
static string Format(this (int n, int sum) pair) => $"{pair.n:N0} with sum {pair.sum:N0}";
}
Output:
First 25 abundant odd numbers:
945 with sum 975
1,575 with sum 1,649
2,205 with sum 2,241
2,835 with sum 2,973
3,465 with sum 4,023
4,095 with sum 4,641
4,725 with sum 5,195
5,355 with sum 5,877
5,775 with sum 6,129
5,985 with sum 6,495
6,435 with sum 6,669
6,615 with sum 7,065
6,825 with sum 7,063
7,245 with sum 7,731
7,425 with sum 7,455
7,875 with sum 8,349
8,085 with sum 8,331
8,415 with sum 8,433
8,505 with sum 8,967
8,925 with sum 8,931
9,135 with sum 9,585
9,555 with sum 9,597
9,765 with sum 10,203
10,395 with sum 12,645
11,025 with sum 11,946

The 1000th abundant odd number: 492,975 with sum 519,361

First abundant odd number > 1b: 1,000,000,575 with sum 1,083,561,009

D[edit]

Translation of: C++
import std.stdio;
 
int[] divisors(int n) {
import std.range;
 
int[] divs = [1];
int[] divs2;
 
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int j = n / i;
divs ~= i;
if (i != j) {
divs2 ~= j;
}
}
}
divs ~= retro(divs2).array;
 
return divs;
}
 
int abundantOdd(int searchFrom, int countFrom, int countTo, bool printOne) {
import std.algorithm.iteration;
import std.array;
import std.conv;
 
int count = countFrom;
int n = searchFrom;
for (; count < countTo; n += 2) {
auto divs = divisors(n);
int tot = sum(divs);
if (tot > n) {
count++;
if (printOne && count < countTo) {
continue;
}
auto s = divs.map!(to!string).join(" + ");
if (printOne) {
writefln("%d < %s = %d", n, s, tot);
} else {
writefln("%2d. %5d < %s = %d", count, n, s, tot);
}
}
}
return n;
}
 
void main() {
const int max = 25;
writefln("The first %d abundant odd numbers are:", max);
int n = abundantOdd(1, 0, 25, false);
 
writeln("\nThe one thousandth abundant odd number is:");
abundantOdd(n, 25, 1000, true);
 
writeln("\nThe first abundant odd number above one billion is:");
abundantOdd(cast(int)(1e9 + 1), 0, 1, true);
}
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

Factor[edit]

USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
 
: σ ( n -- sum ) divisors sum ;
: abundant? ( n -- ? ) [ σ ] [ 2 * ] bi > ;
: abundant-odds-from ( n -- list )
dup even? [ 1 + ] when
[ 2 + ] lfrom-by [ abundant? ] lfilter ;
 
: first25 ( -- seq ) 25 1 abundant-odds-from ltake list>array ;
: 1,000th ( -- n ) 1 abundant-odds-from 999 [ cdr ] times car ;
: first>10^9 ( -- n ) 1,000,000,001 abundant-odds-from car ;
 
GENERIC: show ( obj -- )
M: integer show dup σ [ commas ] [email protected] "%-6s σ = %s\n" printf ;
M: array show [ show ] each ;
 
: abundant-odd-numbers-demo ( -- )
first25 "First 25 abundant odd numbers:"
1,000th "1,000th abundant odd number:"
first>10^9 "First abundant odd number > one billion:"
[ print show nl ] [email protected] ;
 
MAIN: abundant-odd-numbers-demo
Output:
First 25 abundant odd numbers:
945    σ = 1,920
1,575  σ = 3,224
2,205  σ = 4,446
2,835  σ = 5,808
3,465  σ = 7,488
4,095  σ = 8,736
4,725  σ = 9,920
5,355  σ = 11,232
5,775  σ = 11,904
5,985  σ = 12,480
6,435  σ = 13,104
6,615  σ = 13,680
6,825  σ = 13,888
7,245  σ = 14,976
7,425  σ = 14,880
7,875  σ = 16,224
8,085  σ = 16,416
8,415  σ = 16,848
8,505  σ = 17,472
8,925  σ = 17,856
9,135  σ = 18,720
9,555  σ = 19,152
9,765  σ = 19,968
10,395 σ = 23,040
11,025 σ = 22,971

1,000th abundant odd number:
492,975 σ = 1,012,336

First abundant odd number > one billion:
1,000,000,575 σ = 2,083,561,584

FreeBASIC[edit]

Translation of: Visual Basic .NET
 
Declare Function SumaDivisores(n As Integer) As Integer
 
Dim numimpar As Integer = 1
Dim contar As Integer = 0
Dim sumaDiv As Integer = 0
 
Function SumaDivisores(n As Integer) As Integer
' Devuelve la suma de los divisores propios de n
Dim suma As Integer = 1
Dim As Integer d, otroD
 
For d = 2 To Cint(Sqr(n))
If n Mod d = 0 Then
suma += d
otroD = n \ d
If otroD <> d Then suma += otroD
End If
Next d
Return suma
End Function
 
' Encontrar los números requeridos por la tarea:
 
' primeros 25 números abundantes impares
Print "Los primeros 25 números impares abundantes:"
Do While contar < 25
sumaDiv = SumaDivisores(numimpar)
If sumaDiv > numimpar Then
contar += 1
Print using "######"; numimpar;
Print " suma divisoria adecuada: " & sumaDiv
End If
numimpar += 2
Loop
 
' 1000er número impar abundante
Do While contar < 1000
sumaDiv = SumaDivisores(numimpar)
If sumaDiv > numimpar Then contar += 1
numimpar += 2
Loop
Print Chr(10) & "1000º número impar abundante:"
Print " " & (numimpar - 2) & " suma divisoria adecuada: " & sumaDiv
 
' primer número impar abundante > mil millones (millardo)
numimpar = 1000000001
Dim encontrado As Boolean = False
Do While Not encontrado
sumaDiv = SumaDivisores(numimpar)
If sumaDiv > numimpar Then
encontrado = True
Print Chr(10) & "Primer número impar abundante > 1 000 000 000:"
Print " " & numimpar & " suma divisoria adecuada: " & sumaDiv
End If
numimpar += 2
Loop
End
 
Output:
Los primeros 25 números impares abundantes:
   945 suma divisoria adecuada: 975
  1575 suma divisoria adecuada: 1649
  2205 suma divisoria adecuada: 2241
  2835 suma divisoria adecuada: 2973
  3465 suma divisoria adecuada: 4023
  4095 suma divisoria adecuada: 4641
  4725 suma divisoria adecuada: 5195
  5355 suma divisoria adecuada: 5877
  5775 suma divisoria adecuada: 6129
  5985 suma divisoria adecuada: 6495
  6435 suma divisoria adecuada: 6669
  6615 suma divisoria adecuada: 7065
  6825 suma divisoria adecuada: 7063
  7245 suma divisoria adecuada: 7731
  7425 suma divisoria adecuada: 7455
  7875 suma divisoria adecuada: 8349
  8085 suma divisoria adecuada: 8331
  8415 suma divisoria adecuada: 8433
  8505 suma divisoria adecuada: 8967
  8925 suma divisoria adecuada: 8931
  9135 suma divisoria adecuada: 9585
  9555 suma divisoria adecuada: 9597
  9765 suma divisoria adecuada: 10203
 10395 suma divisoria adecuada: 12645
 11025 suma divisoria adecuada: 11946

1000º número impar abundante:
    492975 suma divisoria adecuada: 519361

Primer número impar abundante > 1 000 000 000:
    1000000575 suma divisoria adecuada: 1083561009

Go[edit]

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 abundantOdd(searchFrom, countFrom, countTo int, printOne bool) int {
count := countFrom
n := searchFrom
for ; count < countTo; n += 2 {
divs := divisors(n)
if tot := sum(divs); tot > n {
count++
if printOne && count < countTo {
continue
}
s := sumStr(divs)
if !printOne {
fmt.Printf("%2d. %5d < %s = %d\n", count, n, s, tot)
} else {
fmt.Printf("%d < %s = %d\n", n, s, tot)
}
}
}
return n
}
 
func main() {
const max = 25
fmt.Println("The first", max, "abundant odd numbers are:")
n := abundantOdd(1, 0, 25, false)
 
fmt.Println("\nThe one thousandth abundant odd number is:")
abundantOdd(n, 25, 1000, true)
 
fmt.Println("\nThe first abundant odd number above one billion is:")
abundantOdd(1e9+1, 0, 1, true)
}
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

Haskell[edit]

import Data.List (nub)
 
divisorSum :: Integral a => a -> a
divisorSum n =
sum
. map (\i -> sum $ nub [i, n `quot` i])
. filter ((== 0) . (n `rem`))
$ takeWhile ((<= n) . (^ 2)) [1 ..]
 
oddAbundants :: Integral a => a -> [(a, a)]
oddAbundants n =
[ (i, divisorSum i) | i <- [n ..], odd i, divisorSum i > i * 2 ]
 
printAbundant :: (Int, Int) -> IO ()
printAbundant (n, s) =
putStrLn
$ show n
++ " with "
++ show s
++ " as the sum of all proper divisors."
 
main :: IO ()
main = do
putStrLn "The first 25 odd abundant numbers are:"
mapM_ printAbundant . take 25 $ oddAbundants 1
putStrLn "The 1000th odd abundant number is:"
printAbundant $ oddAbundants 1 !! 1000
putStrLn "The first odd abundant number above 1000000000 is:"
printAbundant . head . oddAbundants $ 10 ^ 9
Output:
The first 25 odd abundant numbers are:
945 with 1920 as the sum of all proper divisors.
1575 with 3224 as the sum of all proper divisors.
2205 with 4446 as the sum of all proper divisors.
2835 with 5808 as the sum of all proper divisors.
3465 with 7488 as the sum of all proper divisors.
4095 with 8736 as the sum of all proper divisors.
4725 with 9920 as the sum of all proper divisors.
5355 with 11232 as the sum of all proper divisors.
5775 with 11904 as the sum of all proper divisors.
5985 with 12480 as the sum of all proper divisors.
6435 with 13104 as the sum of all proper divisors.
6615 with 13680 as the sum of all proper divisors.
6825 with 13888 as the sum of all proper divisors.
7245 with 14976 as the sum of all proper divisors.
7425 with 14880 as the sum of all proper divisors.
7875 with 16224 as the sum of all proper divisors.
8085 with 16416 as the sum of all proper divisors.
8415 with 16848 as the sum of all proper divisors.
8505 with 17472 as the sum of all proper divisors.
8925 with 17856 as the sum of all proper divisors.
9135 with 18720 as the sum of all proper divisors.
9555 with 19152 as the sum of all proper divisors.
9765 with 19968 as the sum of all proper divisors.
10395 with 23040 as the sum of all proper divisors.
11025 with 22971 as the sum of all proper divisors.
The 1000th odd abundant number is:
493185 with 1017792 as the sum of all proper divisors.
The first odd abundant number above 1000000000 is:
1000000575 with 2083561584 as the sum of all proper divisors.


J[edit]

   NB. https://www.math.upenn.edu/~deturck/m170/wk3/lecture/sumdiv.html
   s=: ([: */ [: ((<:@:(^ >:)/) % <:@:{.) __&q:)&>

   assert 6045 -: s 1800

   aliquot_sum=: -~ s

   abundant=: < aliquot_sum

   Filter=: (#~`)(`:6)

   A=: abundant Filter 1 2 p. i. 260000  NB. a batch of abundant odd numbers

   # A   NB. more than 1000, it's enough.
1054

   NB. the first odd abundant numbers
   (,: aliquot_sum) 26 {. A
945 1575 2205 2835 3465 4095 4725 5355 5775 5985 6435 6615 6825 7245 7425 7875 8085 8415 8505 8925 9135 9555  9765 10395 11025 11655
975 1649 2241 2973 4023 4641 5195 5877 6129 6495 6669 7065 7063 7731 7455 8349 8331 8433 8967 8931 9585 9597 10203 12645 11946 12057

   NB. the one thousandth abundant odd number
   (,: aliquot_sum) 999 { A
492975
519361


   k=: adverb def '1000 * m'
   1x k k k
1000000000

   abundant Filter (1x k k k) + 1 2x p. i. 10x k
1000000575 1000001475 1000001625 1000001835 1000002465 1000003095 1000003725 1000004355 1000004775 1000004985 1000005435 1000005615 1000005825 1000006245 1000006425 1000006875 1000007505 1000008765 1000009395 1000010025 1000010655 1000011285 1000011705 100...

   (,: aliquot_sum) {. abundant Filter (1x k k k) + 1 2x p. i. 10x k
1000000575
1083561009

Julia[edit]

using Primes
 
function propfact(n)
f = [one(n)]
for (p, x) in factor(n)
f = reduce(vcat, [f*p^i for i in 1:x], init=f)
end
pop!(f)
f
end
 
isabundant(n) = sum(propfact(n)) > n
prettyprintfactors(n) = (a = propfact(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
 
function oddabundantsfrom(startingint, needed, nprint=0)
n = isodd(startingint) ? startingint : startingint + 1
count = 0
while count < needed
if isabundant(n)
if nprint == 0
prettyprintfactors(n)
elseif nprint == count + 1
prettyprintfactors(n)
break
end
count += 1
end
n += 2
end
end
 
println("First 25 abundant odd numbers:")
oddabundantsfrom(2, 25)
 
println("The thousandth abundant odd number:")
oddabundantsfrom(2, 1001, 1000)
 
println("The first abundant odd number greater than one billion:")
oddabundantsfrom(1000000000, 1)
 
Output:
First 25 abundant odd numbers:
945 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315], these sum to 975.
1575 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525], these sum to 1649.
2205 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 49, 147, 441, 245, 735], these sum to 2241.
2835 has proper divisors [1, 3, 9, 27, 81, 5, 15, 45, 135, 405, 7, 21, 63, 189, 567, 35, 105, 315, 945], these sum to 2973.
3465 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 11, 33, 99, 55, 165, 495, 77, 231, 693, 385, 1155], these sum to 4023.
4095 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 13, 39, 117, 65, 195, 585, 91, 273, 819, 455, 1365], these sum to 4641.
4725 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 25, 75, 225, 675, 7, 21, 63, 189, 35, 105, 315, 945, 175, 525, 1575], these sum to 5195.
5355 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 17, 51, 153, 85, 255, 765, 119, 357, 1071, 595, 1785], these sum to 5877.
5775 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 11, 33, 55, 165, 275, 825, 77, 231, 385, 1155, 1925], these sum to 6129.
5985 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 19, 57, 171, 95, 285, 855, 133, 399, 1197, 665, 1995], these sum to 6495.
6435 has proper divisors [1, 3, 9, 5, 15, 45, 11, 33, 99, 55, 165, 495, 13, 39, 117, 65, 195, 585, 143, 429, 1287, 715, 2145], these sum to 6669.
6615 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315, 945, 49, 147, 441, 1323, 245, 735, 2205], these sum to 7065.
6825 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 13, 39, 65, 195, 325, 975, 91, 273, 455, 1365, 2275], these sum to 7063.
7245 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 23, 69, 207, 115, 345, 1035, 161, 483, 1449, 805, 2415], these sum to 7731.
7425 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 25, 75, 225, 675, 11, 33, 99, 297, 55, 165, 495, 1485, 275, 825, 2475], these sum to 7455.
7875 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 125, 375, 1125, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 875, 2625], these sum to 8349.
8085 has proper divisors [1, 3, 5, 15, 7, 21, 35, 105, 49, 147, 245, 735, 11, 33, 55, 165, 77, 231, 385, 1155, 539, 1617, 2695], these sum to 8331.
8415 has proper divisors [1, 3, 9, 5, 15, 45, 11, 33, 99, 55, 165, 495, 17, 51, 153, 85, 255, 765, 187, 561, 1683, 935, 2805], these sum to 8433.
8505 has proper divisors [1, 3, 9, 27, 81, 243, 5, 15, 45, 135, 405, 1215, 7, 21, 63, 189, 567, 1701, 35, 105, 315, 945, 2835], these sum to 8967.
8925 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 17, 51, 85, 255, 425, 1275, 119, 357, 595, 1785, 2975], these sum to 8931.
9135 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 29, 87, 261, 145, 435, 1305, 203, 609, 1827, 1015, 3045], these sum to 9585.
9555 has proper divisors [1, 3, 5, 15, 7, 21, 35, 105, 49, 147, 245, 735, 13, 39, 65, 195, 91, 273, 455, 1365, 637, 1911, 3185], these sum to 9597.
9765 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 31, 93, 279, 155, 465, 1395, 217, 651, 1953, 1085, 3255], these sum to 10203.
10395 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315, 945, 11, 33, 99, 297, 55, 165, 495, 1485, 77, 231, 693, 2079, 385, 1155, 3465], these sum to 12645.
11025 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 49, 147, 441, 245, 735, 2205, 1225, 3675], these sum to 11946.
The thousandth abundant odd number:
492975 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 313, 939, 2817, 1565, 4695, 14085, 7825, 23475, 70425, 2191, 6573, 19719, 10955, 32865, 98595, 54775, 164325], these sum to 519361.
The first abundant odd number greater than one billion:
1000000575 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 49, 147, 441, 245, 735, 2205, 1225, 3675, 11025, 90703, 272109, 816327, 453515, 1360545, 4081635, 2267575, 6802725, 20408175, 634921, 1904763, 5714289, 3174605, 9523815, 28571445, 15873025, 47619075, 142857225, 4444447, 13333341, 40000023, 22222235, 66666705, 200000115, 111111175, 333333525], these sum to 1083561009.

Kotlin[edit]

Translation of: D
fun divisors(n: Int): List<Int> {
val divs = mutableListOf(1)
val divs2 = mutableListOf<Int>()
 
var i = 2
while (i * i <= n) {
if (n % i == 0) {
val j = n / i
divs.add(i)
if (i != j) {
divs2.add(j)
}
}
i++
}
 
divs.addAll(divs2.reversed())
 
return divs
}
 
fun abundantOdd(searchFrom: Int, countFrom: Int, countTo: Int, printOne: Boolean): Int {
var count = countFrom
var n = searchFrom
 
while (count < countTo) {
val divs = divisors(n)
val tot = divs.sum()
if (tot > n) {
count++
if (!printOne || count >= countTo) {
val s = divs.joinToString(" + ")
if (printOne) {
println("$n < $s = $tot")
} else {
println("%2d. %5d < %s = %d".format(count, n, s, tot))
}
}
}
 
n += 2
}
 
return n
}
 
 
fun main() {
val max = 25
println("The first $max abundant odd numbers are:")
val n = abundantOdd(1, 0, 25, false)
 
println("\nThe one thousandth abundant odd number is:")
abundantOdd(n, 25, 1000, true)
 
println("\nThe first abundant odd number above one billion is:")
abundantOdd((1e9 + 1).toInt(), 0, 1, true)
}
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[edit]

Translation of: Perl 6
Library: ntheory
use strict;
use warnings;
use feature 'say';
use ntheory qw/divisor_sum divisors/;
 
sub odd_abundants {
my($start,$count) = @_;
my $n = int(( $start + 2 ) / 3);
$n += 1 if 0 == $n % 2;
$n *= 3;
my @out;
while (@out < $count) {
$n += 6;
next unless (my $ds = divisor_sum($n)) > 2*$n;
my @d = divisors($n);
push @out, sprintf "%6d: divisor sum: %s = %d", $n, join(' + ', @d[0..@d-2]), $ds-$n;
}
@out;
}
 
say 'First 25 abundant odd numbers:';
say for odd_abundants(1, 25);
say "\nOne thousandth abundant odd number:\n", (odd_abundants(1, 1000))[999];
say "\nFirst abundant odd number above one billion:\n", odd_abundants(999_999_999, 1);
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:
492975: divisor sum: 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

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

Perl 6[edit]

Works with: Rakudo version 2019.03
sub odd-abundant (\x) {
my @l = x.is-prime ?? 1 !! flat
1, (3 .. x.sqrt.floor).map: -> \d {
next unless d +& 1;
my \y = x div d;
next if y * d !== x;
d !== y ?? (d, y) !! d
};
@l.sum > x ?? @l.sort !! Empty;
}
 
sub odd-abundants (Int :$start-at is copy) {
$start-at = ( $start-at + 2 ) div 3;
$start-at += $start-at %% 2;
$start-at *= 3;
($start-at, *+6 ... *).hyper.map: {
next unless my $oa = .&odd-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;
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:
492975: divisor sum: 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

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

Phix[edit]

function abundantOdd(integer n, done, lim, bool printAll)
while done<lim do
atom tot = sum(factors(n,-1))
if tot>n then
done += 1
if printAll or done=lim then
string ln = iff(printAll?sprintf("%2d. ",done):"")
printf(1,"%s%,6d (proper sum:%,d)\n",{ln,n,tot})
end if
end if
n += 2
end while
printf(1,"\n")
return n
end function
printf(1,"The first 25 abundant odd numbers are:\n")
integer n = abundantOdd(1, 0, 25, true)
printf(1,"The one thousandth abundant odd number is:")
{} = abundantOdd(n, 25, 1000, false)
printf(1,"The first abundant odd number above one billion is:")
{} = abundantOdd(1e9+1, 0, 1, false)
Output:
The first 25 abundant odd numbers are:
 1.    945 (proper sum:975)
 2.  1,575 (proper sum:1,649)
 3.  2,205 (proper sum:2,241)
 4.  2,835 (proper sum:2,973)
 5.  3,465 (proper sum:4,023)
 6.  4,095 (proper sum:4,641)
 7.  4,725 (proper sum:5,195)
 8.  5,355 (proper sum:5,877)
 9.  5,775 (proper sum:6,129)
10.  5,985 (proper sum:6,495)
11.  6,435 (proper sum:6,669)
12.  6,615 (proper sum:7,065)
13.  6,825 (proper sum:7,063)
14.  7,245 (proper sum:7,731)
15.  7,425 (proper sum:7,455)
16.  7,875 (proper sum:8,349)
17.  8,085 (proper sum:8,331)
18.  8,415 (proper sum:8,433)
19.  8,505 (proper sum:8,967)
20.  8,925 (proper sum:8,931)
21.  9,135 (proper sum:9,585)
22.  9,555 (proper sum:9,597)
23.  9,765 (proper sum:10,203)
24. 10,395 (proper sum:12,645)
25. 11,025 (proper sum:11,946)

The one thousandth abundant odd number is:492,975 (proper sum:519,361)

The first abundant odd number above one billion is:1,000,000,575 (proper sum:1,083,561,009)

PicoLisp[edit]

(de accud (Var Key)
(if (assoc Key (val Var))
(con @ (inc (cdr @)))
(push Var (cons Key 1)) )
Key )
(de **sum (L)
(let S 1
(for I (cdr L)
(inc 'S (** (car L) I)) )
S ) )
(de factor-sum (N)
(if (=1 N)
0
(let
(R NIL
D 2
L (1 2 2 . (4 2 4 2 4 6 2 6 .))
M (sqrt N)
N1 N
S 1 )
(while (>= M D)
(if (=0 (% N1 D))
(setq M
(sqrt (setq N1 (/ N1 (accud 'R D)))) )
(inc 'D (pop 'L)) ) )
(accud 'R N1)
(for I R
(setq S (* S (**sum I))) )
(- S N) ) ) )
(de factor-list NIL
(let (N 1 C 0)
(make
(loop
(when (> (setq @@ (factor-sum N)) N)
(link (cons N @@))
(inc 'C) )
(inc 'N 2)
(T (= C 1000)) ) ) ) )
(let L (factor-list)
(for N 25
(println N (++ L)) )
(println 1000 (last L))
(println
'****
1000000575
(factor-sum 1000000575) ) )
Output:
1 (945 . 975)
2 (1575 . 1649)
3 (2205 . 2241)
4 (2835 . 2973)
5 (3465 . 4023)
6 (4095 . 4641)
7 (4725 . 5195)
8 (5355 . 5877)
9 (5775 . 6129)
10 (5985 . 6495)
11 (6435 . 6669)
12 (6615 . 7065)
13 (6825 . 7063)
14 (7245 . 7731)
15 (7425 . 7455)
16 (7875 . 8349)
17 (8085 . 8331)
18 (8415 . 8433)
19 (8505 . 8967)
20 (8925 . 8931)
21 (9135 . 9585)
22 (9555 . 9597)
23 (9765 . 10203)
24 (10395 . 12645)
25 (11025 . 11946)
1000 (492975 . 519361)
**** 1000000575 1083561009

Python[edit]

Translation of: BASIC256
#!/usr/bin/python
# Abundant odd numbers - Python
 
oddNumber = 1
aCount = 0
dSum = 0
 
from math import sqrt
 
def divisorSum(n):
sum = 1
i = int(sqrt(n)+1)
 
for d in range (2, i):
if n % d == 0:
sum += d
otherD = n // d
if otherD != d:
sum += otherD
return sum
 
print ("The first 25 abundant odd numbers:")
while aCount < 25:
dSum = divisorSum(oddNumber )
if dSum > oddNumber :
aCount += 1
print("{0:5} proper divisor sum: {1}". format(oddNumber ,dSum ))
oddNumber += 2
 
while aCount < 1000:
dSum = divisorSum(oddNumber )
if dSum > oddNumber :
aCount += 1
oddNumber += 2
print ("\n1000th abundant odd number:")
print (" ",(oddNumber - 2)," proper divisor sum: ",dSum)
 
oddNumber = 1000000001
found = False
while not found :
dSum = divisorSum(oddNumber )
if dSum > oddNumber :
found = True
print ("\nFirst abundant odd number > 1 000 000 000:")
print (" ",oddNumber," proper divisor sum: ",dSum)
oddNumber += 2
Output:
The first 25 abundant odd numbers:
  945 proper divisor sum: 975
 1575 proper divisor sum: 1649
 2205 proper divisor sum: 2241
 2835 proper divisor sum: 2973
 3465 proper divisor sum: 4023
 4095 proper divisor sum: 4513
 4725 proper divisor sum: 5195
 5355 proper divisor sum: 5877
 5775 proper divisor sum: 5977
 5985 proper divisor sum: 6495
 6435 proper divisor sum: 6669
 6615 proper divisor sum: 7065
 6825 proper divisor sum: 7063
 7245 proper divisor sum: 7731
 7425 proper divisor sum: 7455
 7875 proper divisor sum: 8349
 8085 proper divisor sum: 8331
 8415 proper divisor sum: 8433
 8505 proper divisor sum: 8967
 8925 proper divisor sum: 8931
 9135 proper divisor sum: 9585
 9555 proper divisor sum: 9597
 9765 proper divisor sum: 10203
10395 proper divisor sum: 12645
11025 proper divisor sum: 11946

1000th abundant odd number:
     492975  proper divisor sum:  519361

First abundant odd number > 1 000 000 000:
     1000000575  proper divisor sum:  1083561009

Racket[edit]

#lang racket
 
(require math/number-theory
racket/generator)
 
(define (make-generator start)
(in-generator
(for ([n (in-naturals start)] #:when (odd? n))
(define divisor-sum (- (apply + (divisors n)) n))
(when (> divisor-sum n) (yield (list n divisor-sum))))))
 
(for/list ([i (in-range 25)] [x (make-generator 0)]) x) ; Task 1
(for/last ([i (in-range 1000)] [x (make-generator 0)]) x) ; Task 2
(for/first ([x (make-generator (add1 (inexact->exact 1e9)))]) x) ; Task 3
Output:
'((945 975)
  (1575 1649)
  (2205 2241)
  (2835 2973)
  (3465 4023)
  (4095 4641)
  (4725 5195)
  (5355 5877)
  (5775 6129)
  (5985 6495)
  (6435 6669)
  (6615 7065)
  (6825 7063)
  (7245 7731)
  (7425 7455)
  (7875 8349)
  (8085 8331)
  (8415 8433)
  (8505 8967)
  (8925 8931)
  (9135 9585)
  (9555 9597)
  (9765 10203)
  (10395 12645)
  (11025 11946))
'(492975 519361)
'(1000000575 1083561009)

REXX[edit]

A wee bit of coding was added to add commas (because of the larger numbers) as well as alignment of the output.

/*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 #<Nuno then iterate /*Odd abundant# count<Nuno? Then skip.*/
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: 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. */
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: 492,975               sigma=   519,361

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

Ring[edit]

 
#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
 
working...
wait for done...
1. 945: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975

2. 1575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649

3. 2205: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241

4. 2835: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

25. 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:
1000. 492975: divisor sum: 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

First abundant odd number above one billion:
100000000. 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
done...

Ruby[edit]

proper_divisors method taken from http://rosettacode.org/wiki/Proper_divisors#Ruby

require "prime"
 
class Integer
def proper_divisors
return [] if self == 1
primes = prime_division.flat_map{|prime, freq| [prime] * freq}
(1...primes.size).each_with_object([1]) do |n, res|
primes.combination(n).map{|combi| res << combi.inject(:*)}
end.flatten.uniq
end
end
 
def generator_odd_abundants(from=1)
from += 1 if from.even?
Enumerator.new do |y|
from.step(nil, 2) do |n|
sum = n.proper_divisors.sum
y << [n, sum] if sum > n
end
end
end
 
generator_odd_abundants.take(25).each{|n, sum| puts "#{n} with sum #{sum}" }
puts "\n%d with sum %#d" % generator_odd_abundants.take(1000).last
puts "\n%d with sum %#d" % generator_odd_abundants(1_000_000_000).next
 

Rust[edit]

Translation of: Go
fn divisors(n: u64) -> Vec<u64> {
let mut divs = vec![1];
let mut divs2 = Vec::new();
 
for i in (2..).take_while(|x| x * x <= n).filter(|x| n % x == 0) {
divs.push(i);
let j = n / i;
if i != j {
divs2.push(j);
}
}
divs.extend(divs2.iter().rev());
 
divs
}
 
fn sum_string(v: Vec<u64>) -> String {
v[1..]
.iter()
.fold(format!("{}", v[0]), |s, i| format!("{} + {}", s, i))
}
 
fn abundant_odd(search_from: u64, count_from: u64, count_to: u64, print_one: bool) -> u64 {
let mut count = count_from;
for n in (search_from..).step_by(2) {
let divs = divisors(n);
let total: u64 = divs.iter().sum();
if total > n {
count += 1;
let s = sum_string(divs);
if !print_one {
println!("{}. {} < {} = {}", count, n, s, total);
} else if count == count_to {
println!("{} < {} = {}", n, s, total);
}
}
if count == count_to {
break;
}
}
count_to
}
 
fn main() {
let max = 25;
println!("The first {} abundant odd numbers are:", max);
let n = abundant_odd(1, 0, max, false);
 
println!("The one thousandth abundant odd number is:");
abundant_odd(n, 25, 1000, true);
 
println!("The first abundant odd number above one billion is:");
abundant_odd(1e9 as u64 + 1, 0, 1, true);
}
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:
479115 < 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 27 + 35 + 39 + 45 + 63 + 65 + 81 + 91 + 105 + 117 + 135 + 169 + 189 + 195 + 273 + 315 + 351 + 405 + 455 + 507 + 567 + 585 + 819 + 845 + 945 + 1053 + 1183 + 1365 + 1521 + 1755 + 2457 + 2535 + 2835 + 3549 + 4095 + 4563 + 5265 + 5915 + 7371 + 7605 + 10647 + 12285 + 13689 + 17745 + 22815 + 31941 + 36855 + 53235 + 68445 + 95823 + 159705 = 583749
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

Scala[edit]

Translation of: D
import scala.collection.mutable.ListBuffer
 
object Abundant {
def divisors(n: Int): ListBuffer[Int] = {
val divs = new ListBuffer[Int]
divs.append(1)
 
val divs2 = new ListBuffer[Int]
var i = 2
 
while (i * i <= n) {
if (n % i == 0) {
val j = n / i
divs.append(i)
if (i != j) {
divs2.append(j)
}
}
i += 1
}
 
divs.appendAll(divs2.reverse)
divs
}
 
def abundantOdd(searchFrom: Int, countFrom: Int, countTo: Int, printOne: Boolean): Int = {
var count = countFrom
var n = searchFrom
while (count < countTo) {
val divs = divisors(n)
val tot = divs.sum
if (tot > n) {
count += 1
if (!printOne || !(count < countTo)) {
val s = divs.map(a => a.toString).mkString(" + ")
if (printOne) {
printf("%d < %s = %d\n", n, s, tot)
} else {
printf("%2d. %5d < %s = %d\n", count, n, s, tot)
}
}
}
n += 2
}
 
n
}
 
def main(args: Array[String]): Unit = {
val max = 25
printf("The first %d abundant odd numbers are:\n", max)
val n = abundantOdd(1, 0, max, printOne = false)
 
printf("\nThe one thousandth abundant odd number is:\n")
abundantOdd(n, 25, 1000, printOne = true)
 
printf("\nThe first abundant odd number above one billion is:\n")
abundantOdd((1e9 + 1).intValue(), 0, 1, printOne = true)
}
}
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

Sidef[edit]

func is_abundant(n) {
n.sigma > 2*n
}
 
func odd_abundants (from = 1) {
from = (from + 2)//3
from += (from%2 - 1)
3*from .. Inf `by` 6 -> lazy.grep(is_abundant)
}
 
say " Index | Number | proper divisor sum"
const sep = "-------+-------------+-------------------\n"
const fstr = "%6s | %11s | %11s\n"
 
print sep
 
odd_abundants().first(25).each_kv {|k,n|
printf(fstr, k+1, n, n.sigma-n)
}
 
with (odd_abundants().nth(1000)) {|n|
printf(sep + fstr, 1000, n, n.sigma-n)
}
 
with(odd_abundants(1e9).first) {|n|
printf(sep + fstr, '***', n, n.sigma-n)
}
Output:
 Index |      Number | proper divisor sum
-------+-------------+-------------------
     1 |         945 |         975
     2 |        1575 |        1649
     3 |        2205 |        2241
     4 |        2835 |        2973
     5 |        3465 |        4023
     6 |        4095 |        4641
     7 |        4725 |        5195
     8 |        5355 |        5877
     9 |        5775 |        6129
    10 |        5985 |        6495
    11 |        6435 |        6669
    12 |        6615 |        7065
    13 |        6825 |        7063
    14 |        7245 |        7731
    15 |        7425 |        7455
    16 |        7875 |        8349
    17 |        8085 |        8331
    18 |        8415 |        8433
    19 |        8505 |        8967
    20 |        8925 |        8931
    21 |        9135 |        9585
    22 |        9555 |        9597
    23 |        9765 |       10203
    24 |       10395 |       12645
    25 |       11025 |       11946
-------+-------------+-------------------
  1000 |      492975 |      519361
-------+-------------+-------------------
   *** |  1000000575 |  1083561009

Visual Basic .NET[edit]

Translation of: ALGOL 68
Module AbundantOddNumbers
' find some abundant odd numbers - numbers where the sum of the proper
' divisors is bigger than the number
' itself
 
' returns the sum of the proper divisors of n
Private Function divisorSum(n As Integer) As Integer
Dim sum As Integer = 1
For d As Integer = 2 To Math.Round(Math.Sqrt(n))
If n Mod d = 0 Then
sum += d
Dim otherD As Integer = n \ d
IF otherD <> d Then
sum += otherD
End If
End If
Next d
Return sum
End Function
 
' find numbers required by the task
Public Sub Main(args() As String)
' first 25 odd abundant numbers
Dim oddNumber As Integer = 1
Dim aCount As Integer = 0
Dim dSum As Integer = 0
Console.Out.WriteLine("The first 25 abundant odd numbers:")
Do While aCount < 25
dSum = divisorSum(oddNumber)
If dSum > oddNumber Then
aCount += 1
Console.Out.WriteLine(oddNumber.ToString.PadLeft(6) & " proper divisor sum: " & dSum)
End If
oddNumber += 2
Loop
' 1000th odd abundant number
Do While aCount < 1000
dSum = divisorSum(oddNumber)
If dSum > oddNumber Then
aCount += 1
End If
oddNumber += 2
Loop
Console.Out.WriteLine("1000th abundant odd number:")
Console.Out.WriteLine(" " & (oddNumber - 2) & " proper divisor sum: " & dSum)
' first odd abundant number > one billion
oddNumber = 1000000001
Dim found As Boolean = False
Do While Not found
dSum = divisorSum(oddNumber)
If dSum > oddNumber Then
found = True
Console.Out.WriteLine("First abundant odd number > 1 000 000 000:")
Console.Out.WriteLine(" " & oddNumber & " proper divisor sum: " & dSum)
End If
oddNumber += 2
Loop
End Sub
End Module
Output:
The first 25 abundant odd numbers:
   945 proper divisor sum: 975
  1575 proper divisor sum: 1649
  2205 proper divisor sum: 2241
  2835 proper divisor sum: 2973
  3465 proper divisor sum: 4023
  4095 proper divisor sum: 4641
  4725 proper divisor sum: 5195
  5355 proper divisor sum: 5877
  5775 proper divisor sum: 6129
  5985 proper divisor sum: 6495
  6435 proper divisor sum: 6669
  6615 proper divisor sum: 7065
  6825 proper divisor sum: 7063
  7245 proper divisor sum: 7731
  7425 proper divisor sum: 7455
  7875 proper divisor sum: 8349
  8085 proper divisor sum: 8331
  8415 proper divisor sum: 8433
  8505 proper divisor sum: 8967
  8925 proper divisor sum: 8931
  9135 proper divisor sum: 9585
  9555 proper divisor sum: 9597
  9765 proper divisor sum: 10203
 10395 proper divisor sum: 12645
 11025 proper divisor sum: 11946
1000th abundant odd number:
    492975 proper divisor sum: 519361
First abundant odd number > 1 000 000 000:
    1000000575 proper divisor sum: 1083561009

zkl[edit]

fcn oddAbundants(startAt=3){  //--> iterator
Walker.zero().tweak(fcn(rn){
n:=rn.value;
while(True){
sum:=0;
foreach d in ([3.. n.toFloat().sqrt().toInt(), 2]){
if( (y:=n/d) *d != n) continue;
sum += ((y==d) and y or y+d)
}
if(sum>n){ rn.set(n+2); return(n) }
n+=2;
}
}.fp(Ref(startAt.isOdd and startAt or startAt+1)))
}
fcn oddDivisors(n){  // -->sorted List
[3.. n.toFloat().sqrt().toInt(), 2].pump(List(1),'wrap(d){
if( (y:=n/d) *d != n) return(Void.Skip);
if (y==d) y else T(y,d)
}).flatten().sort()
}
fcn printOAs(oas){ // List | int
foreach n in (vm.arglist.flatten()){
ds:=oddDivisors(n);
println("%6,d: %6,d = %s".fmt(n, ds.sum(0), ds.sort().concat(" + ")))
}
}
oaw:=oddAbundants();
 
println("First 25 abundant odd numbers:");
oaw.walk(25) : printOAs(_);
 
println("\nThe one thousandth abundant odd number is:");
oaw.drop(1_000 - 25).value : printOAs(_);
 
println("\nThe first abundant odd number above one billion is:");
printOAs(oddAbundants(1_000_000_000).next());
Output:
   945:    975 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315
 1,575:  1,649 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525
 2,205:  2,241 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735
 2,835:  2,973 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945
 3,465:  4,023 = 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155
 4,095:  4,641 = 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365
 4,725:  5,195 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575
 5,355:  5,877 = 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785
 5,775:  6,129 = 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925
 5,985:  6,495 = 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995
 6,435:  6,669 = 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145
 6,615:  7,065 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205
 6,825:  7,063 = 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275
 7,245:  7,731 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415
 7,425:  7,455 = 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475
 7,875:  8,349 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625
 8,085:  8,331 = 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695
 8,415:  8,433 = 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805
 8,505:  8,967 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835
 8,925:  8,931 = 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975
 9,135:  9,585 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045
 9,555:  9,597 = 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185
 9,765: 10,203 = 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255
10,395: 12,645 = 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
11,025: 11,946 = 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

The one thousandth abundant odd number is:
492,975: 519,361 = 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

The first abundant odd number above one billion is:
1,000,000,575: 1,083,561,009 = 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