Abundant odd numbers: Difference between revisions

→‎{{header|REXX}}: ooRexx conformance and only one loop instead of three
(→‎{{header|REXX}}: ooRexx conformance and only one loop instead of three)
 
(91 intermediate revisions by 43 users not shown)
Line 22:
 
;References:
:*   the [[oeis:A005231|OEIS entry:   [httpA005231://oeis.org/A005231 oddOdd abundant numbers (odd numbers n whose sum of divisors exceeds 2n)]. ]
:*   American Journal of Mathematics, Vol. 35, No. 4 (Oct., 1913), pp. 413-422 - Finiteness of the Odd Perfect and Primitive Abundant Numbers with n Distinct Prime Factors (LE Dickson)
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V oddNumber = 1
V aCount = 0
V dSum = 0
 
F divisorSum(n)
V sum = 1
V i = Int(sqrt(n) + 1)
 
L(d) 2 .< i
I n % d == 0
sum += d
V otherD = n I/ d
I otherD != d
sum += otherD
R sum
 
print(‘The first 25 abundant odd numbers:’)
L aCount < 25
dSum = divisorSum(oddNumber)
I dSum > oddNumber
aCount++
print(‘#5 proper divisor sum: #.’.format(oddNumber, dSum))
oddNumber += 2
 
L aCount < 1000
dSum = divisorSum(oddNumber)
I dSum > oddNumber
aCount++
oddNumber += 2
print("\n1000th abundant odd number:")
print(‘ ’(oddNumber - 2)‘ proper divisor sum: ’dSum)
 
oddNumber = 1000000001
V found = 0B
L !found
dSum = divisorSum(oddNumber)
I dSum > oddNumber
found = 1B
print("\nFirst abundant odd number > 1 000 000 000:")
print(‘ ’oddNumber‘ proper divisor sum: ’dSum)
oddNumber += 2</syntaxhighlight>
 
{{out}}
<pre>
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
</pre>
 
=={{header|360 Assembly}}==
<langsyntaxhighlight lang="360asm">* Abundant odd numbers 18/09/2019
ABUNODDS CSECT
USING ABUNODDS,R13 base register
Line 111 ⟶ 192:
XDEC DS CL12 temp for edit
REGEQU equate registers
END ABUNODDS</langsyntaxhighlight>
{{out}}
<pre>
Line 143 ⟶ 224:
</pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program abundant64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ NBDIVISORS, 1000
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessStartPgm: .asciz "Program start \n"
szMessEndPgm: .asciz "Program normal end.\n"
szMessErrorArea: .asciz "\033[31mError : area divisors too small.\n"
szMessError: .asciz "\033[31mError !!!\n"
szMessErrGen: .asciz "Error end program.\n"
szMessNbPrem: .asciz "This number is prime !!!.\n"
szMessOverflow: .asciz "Dépassement de capacité vérification premier.\n"
szMessResultFact: .asciz "// "
szCarriageReturn: .asciz "\n"
/* datas message display */
szMessEntete: .asciz "The first 25 abundant odd numbers are:\n"
szMessResult: .asciz "Number : @ sum : @ \n"
szMessEntete1: .asciz "The 1000 odd abundant number :\n"
szMessEntete2: .asciz "First odd abundant number > 1000000000 :\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
.align 4
sZoneConv: .skip 24
tbZoneDecom: .skip 16 * NBDIVISORS // facteur 8 octets nombre 8 octets
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // program start
ldr x0,qAdrszMessStartPgm // display start message
bl affichageMess
ldr x0,qAdrszMessEntete // display result message
bl affichageMess
mov x2,#1
mov x3,#0
1:
mov x0,x2 // number
bl testAbundant
cmp x0,#1
bne 3f
add x3,x3,#1
mov x0,x2
mov x4,x1 // save sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
mov x5,x0
mov x0,x4 // sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
mov x0,x5
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
bl affichageMess
3:
add x2,x2,#2
cmp x3,#25
blt 1b
/* 1000 abundant number */
ldr x0,qAdrszMessEntete1
bl affichageMess
mov x2,#1
mov x3,#0
4:
mov x0,x2 // number
bl testAbundant
cmp x0,#1
bne 6f
add x3,x3,#1
6:
cmp x3,#1000
cinc x2,x2,lt // add two
cinc x2,x2,lt
blt 4b
mov x0,x2
mov x4,x1 // save sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
mov x5,x0
mov x0,x4 // sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
mov x0,x5
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
bl affichageMess
/* abundant number>1000000000 */
ldr x0,qAdrszMessEntete2
bl affichageMess
ldr x2,iN10P9
add x2,x2,#1
mov x3,#0
7:
mov x0,x2 // number
bl testAbundant
cmp x0,#1
beq 8f
add x2,x2,#2
b 7b
8:
mov x0,x2
mov x4,x1 // save sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
mov x5,x0
mov x0,x4 // sum
ldr x1,qAdrsZoneConv
bl conversion10 // convert ascii string
mov x0,x5
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and put in message
bl affichageMess
ldr x0,qAdrszMessEndPgm // display end message
bl affichageMess
b 100f
99: // display error message
ldr x0,qAdrszMessError
bl affichageMess
100: // standard end of the program
mov x0, #0 // return code
mov x8, #EXIT // request to exit program
svc 0 // perform system call
qAdrszMessStartPgm: .quad szMessStartPgm
qAdrszMessEndPgm: .quad szMessEndPgm
qAdrszMessError: .quad szMessError
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrtbZoneDecom: .quad tbZoneDecom
qAdrszMessEntete: .quad szMessEntete
qAdrszMessEntete1: .quad szMessEntete1
qAdrszMessEntete2: .quad szMessEntete2
qAdrszMessResult: .quad szMessResult
qAdrsZoneConv: .quad sZoneConv
iN10P9: .quad 1000000000
/******************************************************************/
/* test if number is abundant number */
/******************************************************************/
/* x0 contains the number */
/* x0 return 1 if abundant number else return 0 */
/* x1 return sum */
testAbundant:
stp x2,lr,[sp,-16]! // save registres
stp x3,x4,[sp,-16]! // save registres
stp x5,x6,[sp,-16]! // save registres
mov x6,x0 // save number
ldr x1,qAdrtbZoneDecom
bl decompFact // create area of divisors
cmp x0,#1 // no divisors
ble 99f
lsl x5,x6,#1 // abondant number ?
cmp x5,x2
bgt 99f // no -> end
mov x0,#1
sub x1,x2,x6 // sum
b 100f
99:
mov x0,0
100:
ldp x5,x6,[sp],16 // restaur des 2 registres
ldp x3,x4,[sp],16 // restaur des 2 registres
ldp x2,lr,[sp],16 // restaur des 2 registres
ret
/******************************************************************/
/* decomposition en facteur */
/******************************************************************/
/* x0 contient le nombre à decomposer */
decompFact:
stp x3,lr,[sp,-16]! // save registres
stp x4,x5,[sp,-16]! // save registres
stp x6,x7,[sp,-16]! // save registres
stp x8,x9,[sp,-16]! // save registres
stp x10,x11,[sp,-16]! // save registres
mov x5,x1
mov x8,x0 // save number
bl isPrime // prime ?
cmp x0,#1
beq 98f // yes is prime
mov x1,#1
str x1,[x5] // first factor
mov x12,#1 // divisors sum
mov x11,#1 // number odd divisors
mov x4,#1 // indice divisors table
mov x1,#2 // first divisor
mov x6,#0 // previous divisor
mov x7,#0 // number of same divisors
2:
mov x0,x8 // dividende
udiv x2,x0,x1 // x1 divisor x2 quotient x3 remainder
msub x3,x2,x1,x0
cmp x3,#0
bne 5f // if remainder <> zero -> no divisor
mov x8,x2 // else quotient -> new dividende
cmp x1,x6 // same divisor ?
beq 4f // yes
mov x7,x4 // number factors in table
mov x9,#0 // indice
21:
ldr x10,[x5,x9,lsl #3 ] // load one factor
mul x10,x1,x10 // multiply
str x10,[x5,x7,lsl #3] // and store in the table
tst x10,#1 // divisor odd ?
cinc x11,x11,ne
add x12,x12,x10
add x7,x7,#1 // and increment counter
add x9,x9,#1
cmp x9,x4
blt 21b
mov x4,x7
mov x6,x1 // new divisor
b 7f
4: // same divisor
sub x9,x4,#1
mov x7,x4
41:
ldr x10,[x5,x9,lsl #3 ]
cmp x10,x1
sub x13,x9,1
csel x9,x13,x9,ne
bne 41b
sub x9,x4,x9
42:
ldr x10,[x5,x9,lsl #3 ]
mul x10,x1,x10
str x10,[x5,x7,lsl #3] // and store in the table
tst x10,#1 // divsor odd ?
cinc x11,x11,ne
add x12,x12,x10
add x7,x7,#1 // and increment counter
add x9,x9,#1
cmp x9,x4
blt 42b
mov x4,x7
b 7f // and loop
/* not divisor -> increment next divisor */
5:
cmp x1,#2 // if divisor = 2 -> add 1
add x13,x1,#1 // add 1
add x14,x1,#2 // else add 2
csel x1,x13,x14,eq
b 2b
/* divisor -> test if new dividende is prime */
7:
mov x3,x1 // save divisor
cmp x8,#1 // dividende = 1 ? -> end
beq 10f
mov x0,x8 // new dividende is prime ?
mov x1,#0
bl isPrime // the new dividende is prime ?
cmp x0,#1
bne 10f // the new dividende is not prime
cmp x8,x6 // else dividende is same divisor ?
beq 9f // yes
mov x7,x4 // number factors in table
mov x9,#0 // indice
71:
ldr x10,[x5,x9,lsl #3 ] // load one factor
mul x10,x8,x10 // multiply
str x10,[x5,x7,lsl #3] // and store in the table
tst x10,#1 // divsor odd ?
cinc x11,x11,ne
add x12,x12,x10
add x7,x7,#1 // and increment counter
add x9,x9,#1
cmp x9,x4
blt 71b
mov x4,x7
mov x7,#0
b 11f
9:
sub x9,x4,#1
mov x7,x4
91:
ldr x10,[x5,x9,lsl #3 ]
cmp x10,x8
sub x13,x9,#1
csel x9,x13,x9,ne
bne 91b
sub x9,x4,x9
92:
ldr x10,[x5,x9,lsl #3 ]
mul x10,x8,x10
str x10,[x5,x7,lsl #3] // and store in the table
tst x10,#1 // divisor odd ?
cinc x11,x11,ne
add x12,x12,x10
add x7,x7,#1 // and increment counter
add x9,x9,#1
cmp x9,x4
blt 92b
mov x4,x7
b 11f
10:
mov x1,x3 // current divisor = new divisor
cmp x1,x8 // current divisor > new dividende ?
ble 2b // no -> loop
/* end decomposition */
11:
mov x0,x4 // return number of table items
mov x2,x12 // return sum
mov x1,x11 // return number of odd divisor
mov x3,#0
str x3,[x5,x4,lsl #3] // store zéro in last table item
b 100f
98:
//ldr x0,qAdrszMessNbPrem
//bl affichageMess
mov x0,#1 // return code
b 100f
99:
ldr x0,qAdrszMessError
bl affichageMess
mov x0,#-1 // error code
b 100f
 
 
100:
ldp x10,x11,[sp],16 // restaur des 2 registres
ldp x8,x9,[sp],16 // restaur des 2 registres
ldp x6,x7,[sp],16 // restaur des 2 registres
ldp x4,x5,[sp],16 // restaur des 2 registres
ldp x3,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
qAdrszMessErrGen: .quad szMessErrGen
qAdrszMessNbPrem: .quad szMessNbPrem
/***************************************************/
/* Verification si un nombre est premier */
/***************************************************/
/* x0 contient le nombre à verifier */
/* x0 retourne 1 si premier 0 sinon */
isPrime:
stp x1,lr,[sp,-16]! // save registres
stp x2,x3,[sp,-16]! // save registres
mov x2,x0
sub x1,x0,#1
cmp x2,0
beq 99f // retourne zéro
cmp x2,2 // pour 1 et 2 retourne 1
ble 2f
mov x0,#2
bl moduloPux64
bcs 100f // erreur overflow
cmp x0,#1
bne 99f // Pas premier
cmp x2,3
beq 2f
mov x0,#3
bl moduloPux64
blt 100f // erreur overflow
cmp x0,#1
bne 99f
 
cmp x2,5
beq 2f
mov x0,#5
bl moduloPux64
bcs 100f // erreur overflow
cmp x0,#1
bne 99f // Pas premier
 
cmp x2,7
beq 2f
mov x0,#7
bl moduloPux64
bcs 100f // erreur overflow
cmp x0,#1
bne 99f // Pas premier
 
cmp x2,11
beq 2f
mov x0,#11
bl moduloPux64
bcs 100f // erreur overflow
cmp x0,#1
bne 99f // Pas premier
 
cmp x2,13
beq 2f
mov x0,#13
bl moduloPux64
bcs 100f // erreur overflow
cmp x0,#1
bne 99f // Pas premier
2:
cmn x0,0 // carry à zero pas d'erreur
mov x0,1 // premier
b 100f
99:
cmn x0,0 // carry à zero pas d'erreur
mov x0,#0 // Pas premier
100:
ldp x2,x3,[sp],16 // restaur des 2 registres
ldp x1,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
 
/**************************************************************/
/********************************************************/
/* Calcul modulo de b puissance e modulo m */
/* Exemple 4 puissance 13 modulo 497 = 445 */
/********************************************************/
/* x0 nombre */
/* x1 exposant */
/* x2 modulo */
moduloPux64:
stp x1,lr,[sp,-16]! // save registres
stp x3,x4,[sp,-16]! // save registres
stp x5,x6,[sp,-16]! // save registres
stp x7,x8,[sp,-16]! // save registres
stp x9,x10,[sp,-16]! // save registres
cbz x0,100f
cbz x1,100f
mov x8,x0
mov x7,x1
mov x6,1 // resultat
udiv x4,x8,x2
msub x9,x4,x2,x8 // contient le reste
1:
tst x7,1
beq 2f
mul x4,x9,x6
umulh x5,x9,x6
//cbnz x5,99f
mov x6,x4
mov x0,x6
mov x1,x5
bl divisionReg128U
cbnz x1,99f // overflow
mov x6,x3
2:
mul x8,x9,x9
umulh x5,x9,x9
mov x0,x8
mov x1,x5
bl divisionReg128U
cbnz x1,99f // overflow
mov x9,x3
lsr x7,x7,1
cbnz x7,1b
mov x0,x6 // result
cmn x0,0 // carry à zero pas d'erreur
b 100f
99:
ldr x1,qAdrszMessOverflow
bl afficheErreur
cmp x0,0 // carry à un car erreur
mov x0,-1 // code erreur
 
100:
ldp x9,x10,[sp],16 // restaur des 2 registres
ldp x7,x8,[sp],16 // restaur des 2 registres
ldp x5,x6,[sp],16 // restaur des 2 registres
ldp x3,x4,[sp],16 // restaur des 2 registres
ldp x1,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
qAdrszMessOverflow: .quad szMessOverflow
/***************************************************/
/* division d un nombre de 128 bits par un nombre de 64 bits */
/***************************************************/
/* x0 contient partie basse dividende */
/* x1 contient partie haute dividente */
/* x2 contient le diviseur */
/* x0 retourne partie basse quotient */
/* x1 retourne partie haute quotient */
/* x3 retourne le reste */
divisionReg128U:
stp x6,lr,[sp,-16]! // save registres
stp x4,x5,[sp,-16]! // save registres
mov x5,#0 // raz du reste R
mov x3,#128 // compteur de boucle
mov x4,#0 // dernier bit
1:
lsl x5,x5,#1 // on decale le reste de 1
tst x1,1<<63 // test du bit le plus à gauche
lsl x1,x1,#1 // on decale la partie haute du quotient de 1
beq 2f
orr x5,x5,#1 // et on le pousse dans le reste R
2:
tst x0,1<<63
lsl x0,x0,#1 // puis on decale la partie basse
beq 3f
orr x1,x1,#1 // et on pousse le bit de gauche dans la partie haute
3:
orr x0,x0,x4 // position du dernier bit du quotient
mov x4,#0 // raz du bit
cmp x5,x2
blt 4f
sub x5,x5,x2 // on enleve le diviseur du reste
mov x4,#1 // dernier bit à 1
4:
// et boucle
subs x3,x3,#1
bgt 1b
lsl x1,x1,#1 // on decale le quotient de 1
tst x0,1<<63
lsl x0,x0,#1 // puis on decale la partie basse
beq 5f
orr x1,x1,#1
5:
orr x0,x0,x4 // position du dernier bit du quotient
mov x3,x5
100:
ldp x4,x5,[sp],16 // restaur des 2 registres
ldp x6,lr,[sp],16 // restaur des 2 registres
ret // retour adresse lr x30
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
{{output}}
<pre>
Program start
The first 25 abundant odd numbers are:
Number : 945 sum : 975
Number : 1575 sum : 1649
Number : 2205 sum : 2241
Number : 2835 sum : 2973
Number : 3465 sum : 4023
Number : 4095 sum : 4641
Number : 4725 sum : 5195
Number : 5355 sum : 5877
Number : 5775 sum : 6129
Number : 5985 sum : 6495
Number : 6435 sum : 6669
Number : 6615 sum : 7065
Number : 6825 sum : 7063
Number : 7245 sum : 7731
Number : 7425 sum : 7455
Number : 7875 sum : 8349
Number : 8085 sum : 8331
Number : 8415 sum : 8433
Number : 8505 sum : 8967
Number : 8925 sum : 8931
Number : 9135 sum : 9585
Number : 9555 sum : 9597
Number : 9765 sum : 10203
Number : 10395 sum : 12645
Number : 11025 sum : 11946
The 1000 odd abundant number :
Number : 492975 sum : 519361
First odd abundant number > 1000000000 :
Number : 1000000575 sum : 1083561009
Program normal end.
</pre>
=={{header|Ada}}==
 
Line 149 ⟶ 815:
[[http://rosettacode.org/wiki/Proper_divisors#Ada]].
 
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO, Generic_Divisors;
 
procedure Odd_Abundant is
Line 205 ⟶ 871:
end loop;
Print_Abundant_Line(1, Current, False);
end Odd_Abundant;</langsyntaxhighlight>
 
{{out}}
Line 241 ⟶ 907:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN
# find some abundant odd numbers - numbers where the sum of the proper #
# divisors is bigger than the number #
Line 316 ⟶ 982:
OD
END
END</langsyntaxhighlight>
{{out}}
<pre>
Line 351 ⟶ 1,017:
</pre>
 
=={{header|BASIC256ALGOL W}}==
{{Trans|ALGOL 68}}
Using the divisor_sum procedure from the [[Sum_of_divisors#ALGOL_W]] task.
<syntaxhighlight lang="algolw">begin
% find some abundant odd numbers - numbers where the sum of the proper %
% divisors is bigger than the number %
% itself %
 
% computes the sum of the divisors of v using the prime %
% factorisation %
integer procedure divisor_sum( integer value v ) ; begin
integer total, power, n, p;
total := 1; power := 2; n := v;
% Deal with powers of 2 first %
while not odd( n ) do begin
total := total + power;
power := power * 2;
n := n div 2
end while_not_odd_n ;
% Odd prime factors up to the square root %
p := 3;
while ( p * p ) <= n do begin
integer sum;
sum := 1;
power := p;
while n rem p = 0 do begin
sum := sum + power;
power := power * p;
n := n div p
end while_n_rem_p_eq_0 ;
p := p + 2;
total := total * sum
end while_p_x_p_le_n ;
% If n > 1 then it's prime %
if n > 1 then total := total * ( n + 1 );
total
end divisor_sum ;
% returns the sum of the proper divisors of v %
integer procedure divisorSum( integer value v ) ;
if v < 2 then 0 else divisor_sum( v ) - v;
% find numbers required by the task %
begin
integer aCount, oddNumber, dSum;
logical foundOddAn;
% first 25 odd abundant numbers %
oddNumber := 1;
aCount := 0;
write( "The first 25 abundant odd numbers:" );
while aCount < 25 do begin
dSum := divisorSum( oddNumber );
if dSum > oddNumber then begin
aCount := aCount + 1;
write( i_w := 6, oddNumber, " proper divisor sum: ", dSum )
end if_dSum_gt_oddNumber ;
oddNumber := oddNumber + 2
end while_aCount_lt_1000 ;
% 1000th odd abundant number %
while aCount < 1000 do begin
dSum := divisorSum( oddNumber );
if dSum > oddNumber then aCount := aCount + 1;
oddNumber := oddNumber + 2
end while_aCount_lt_1000 ;
write( "1000th abundant odd number: " );
write( oddNumber - 2, " proper divisor sum: ", dSum );
% first odd abundant number > one billion %
oddNumber := 1000000001;
foundOddAn := false;
while not foundOddAn do begin
dSum := divisorSum( oddNumber );
if dSum > oddNumber then begin
foundOddAn := true;
write( "First abundant odd number > 1000000000: " );
write( oddNumber, " proper divisor sum: ", dSum )
end if_dSum_gt_oddNumber ;
oddNumber := oddNumber + 2
end while_not_foundOddAn ;
end
end.</syntaxhighlight>
{{out}}
<pre>
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 > 1000000000:
1000000575 proper divisor sum: 1083561009
</pre>
 
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set sum to sum + limit
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i is 0) then set sum to sum + i + n div i
end repeat
return sum
end aliquotSum
 
-- Task code:
local output, counter, n, sum, astid
set output to {"The first 25 abundant odd numbers:"}
set counter to 0
set n to 1
repeat until (counter = 25)
set sum to aliquotSum(n)
if (sum > n) then
set end of output to " " & n & " (proper divisor sum: " & sum & ")"
set counter to counter + 1
end if
set n to n + 2
end repeat
 
set end of output to "The one thousandth:"
repeat until (counter = 1000)
set sum to aliquotSum(n)
if (sum > n) then set counter to counter + 1
set n to n + 2
end repeat
set end of output to " " & (n - 2) & " (proper divisor sum: " & sum & ")"
 
set end of output to "The first > 1,000,000,000:"
set n to 1.000000001E+9
set sum to aliquotSum(n)
repeat until (sum > n)
set n to n + 2
set sum to aliquotSum(n)
end repeat
set end of output to " " & (n div 1000000) & text 2 thru -1 of ((1000000 + ((n mod 1000000) as integer)) as text) & ¬
" (proper divisor sum: " & (sum div 1000000) & text 2 thru -1 of ((1000000 + ((sum mod 1000000) as integer)) as text) & ")"
 
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output</syntaxhighlight>
 
{{output}}
 
<syntaxhighlight lang="applescript">"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)
The one thousandth:
492975 (proper divisor sum: 519361)
The first > 1,000,000,000:
1000000575 (proper divisor sum: 1083561009)"</syntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
/* program abundant.s */
 
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constantes see task include a file in arm assembly */
/************************************/
/* Constantes */
/************************************/
.include "../constantes.inc"
 
.equ NBDIVISORS, 1000
 
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessStartPgm: .asciz "Program start \n"
szMessEndPgm: .asciz "Program normal end.\n"
szMessErrorArea: .asciz "\033[31mError : area divisors too small.\n"
szMessError: .asciz "\033[31mError !!!\n"
szMessErrGen: .asciz "Error end program.\n"
szMessNbPrem: .asciz "This number is prime !!!.\n"
szMessResultFact: .asciz "@ "
 
szCarriageReturn: .asciz "\n"
 
/* datas message display */
szMessEntete: .asciz "The first 25 abundant odd numbers are:\n"
szMessResult: .asciz "Number : @ sum : @ \n"
 
szMessEntete1: .asciz "The 1000 odd abundant number :\n"
szMessEntete2: .asciz "First odd abundant number > 1000000000 :\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
.align 4
sZoneConv: .skip 24
tbZoneDecom: .skip 4 * NBDIVISORS // facteur 4 octets
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: @ program start
ldr r0,iAdrszMessStartPgm @ display start message
bl affichageMess
 
ldr r0,iAdrszMessEntete @ display result message
bl affichageMess
mov r2,#1
mov r3,#0
1:
mov r0,r2 @ number
bl testAbundant
cmp r0,#1
bne 3f
add r3,#1
mov r0,r2
mov r4,r1 @ save sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
ldr r0,iAdrszMessResult
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
mov r5,r0
mov r0,r4 @ sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
mov r0,r5
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
 
bl affichageMess
3:
add r2,r2,#2
cmp r3,#25
blt 1b
 
/* 1000 abundant number */
ldr r0,iAdrszMessEntete1
bl affichageMess
mov r2,#1
mov r3,#0
4:
mov r0,r2 @ number
bl testAbundant
cmp r0,#1
bne 6f
add r3,#1
6:
cmp r3,#1000
addlt r2,r2,#2
blt 4b
mov r0,r2
mov r4,r1 @ save sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
ldr r0,iAdrszMessResult
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
mov r5,r0
mov r0,r4 @ sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
mov r0,r5
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
 
bl affichageMess
 
/* abundant number>1000000000 */
ldr r0,iAdrszMessEntete2
bl affichageMess
ldr r2,iN10P9
add r2,#1
mov r3,#0
7:
mov r0,r2 @ number
bl testAbundant
cmp r0,#1
beq 8f
add r2,r2,#2
b 7b
8:
mov r0,r2
mov r4,r1 @ save sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
ldr r0,iAdrszMessResult
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
mov r5,r0
mov r0,r4 @ sum
ldr r1,iAdrsZoneConv
bl conversion10 @ convert ascii string
mov r0,r5
ldr r1,iAdrsZoneConv
bl strInsertAtCharInc @ and put in message
 
bl affichageMess
 
 
 
ldr r0,iAdrszMessEndPgm @ display end message
bl affichageMess
b 100f
99: @ display error message
ldr r0,iAdrszMessError
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform system call
iAdrszMessStartPgm: .int szMessStartPgm
iAdrszMessEndPgm: .int szMessEndPgm
iAdrszMessError: .int szMessError
iAdrszCarriageReturn: .int szCarriageReturn
iAdrtbZoneDecom: .int tbZoneDecom
iAdrszMessEntete: .int szMessEntete
iAdrszMessEntete1: .int szMessEntete1
iAdrszMessEntete2: .int szMessEntete2
iAdrszMessResult: .int szMessResult
iAdrsZoneConv: .int sZoneConv
iN10P9: .int 1000000000
/******************************************************************/
/* test if number is abundant number */
/******************************************************************/
/* r0 contains the number */
/* r0 return 1 if Zumkeller number else return 0 */
testAbundant:
push {r2-r6,lr} @ save registers
mov r6,r0 @ save number
ldr r1,iAdrtbZoneDecom
bl decompFact @ create area of divisors
cmp r0,#1 @ no divisors
movle r0,#0
ble 100f
lsl r5,r6,#1 @ abondant number ?
cmp r5,r2
movgt r0,#0
bgt 100f @ no -> end
mov r0,#1
sub r1,r2,r6 @ sum
100:
pop {r2-r6,lr} @ restaur registers
bx lr @ return
 
 
 
/******************************************************************/
/* factor decomposition */
/******************************************************************/
/* r0 contains number */
/* r1 contains address of divisors area */
/* r0 return divisors items in table */
/* r1 return the number of odd divisors */
/* r2 return the sum of divisors */
decompFact:
push {r3-r8,lr} @ save registers
mov r5,r1
mov r8,r0 @ save number
bl isPrime @ prime ?
cmp r0,#1
beq 98f @ yes is prime
mov r1,#1
str r1,[r5] @ first factor
mov r12,#1 @ divisors sum
mov r11,#1 @ number odd divisors
mov r4,#1 @ indice divisors table
mov r1,#2 @ first divisor
mov r6,#0 @ previous divisor
mov r7,#0 @ number of same divisors
2:
mov r0,r8 @ dividende
bl division @ r1 divisor r2 quotient r3 remainder
cmp r3,#0
bne 5f @ if remainder <> zero -> no divisor
mov r8,r2 @ else quotient -> new dividende
cmp r1,r6 @ same divisor ?
beq 4f @ yes
mov r7,r4 @ number factors in table
mov r9,#0 @ indice
21:
ldr r10,[r5,r9,lsl #2 ] @ load one factor
mul r10,r1,r10 @ multiply
str r10,[r5,r7,lsl #2] @ and store in the table
tst r10,#1 @ divisor odd ?
addne r11,#1
add r12,r10
add r7,r7,#1 @ and increment counter
add r9,r9,#1
cmp r9,r4
blt 21b
mov r4,r7
mov r6,r1 @ new divisor
b 7f
4: @ same divisor
sub r9,r4,#1
mov r7,r4
41:
ldr r10,[r5,r9,lsl #2 ]
cmp r10,r1
subne r9,#1
bne 41b
sub r9,r4,r9
42:
ldr r10,[r5,r9,lsl #2 ]
mul r10,r1,r10
str r10,[r5,r7,lsl #2] @ and store in the table
tst r10,#1 @ divsor odd ?
addne r11,#1
add r12,r10
add r7,r7,#1 @ and increment counter
add r9,r9,#1
cmp r9,r4
blt 42b
mov r4,r7
b 7f @ and loop
/* not divisor -> increment next divisor */
5:
cmp r1,#2 @ if divisor = 2 -> add 1
addeq r1,#1
addne r1,#2 @ else add 2
b 2b
/* divisor -> test if new dividende is prime */
7:
mov r3,r1 @ save divisor
cmp r8,#1 @ dividende = 1 ? -> end
beq 10f
mov r0,r8 @ new dividende is prime ?
mov r1,#0
bl isPrime @ the new dividende is prime ?
cmp r0,#1
bne 10f @ the new dividende is not prime
 
cmp r8,r6 @ else dividende is same divisor ?
beq 9f @ yes
mov r7,r4 @ number factors in table
mov r9,#0 @ indice
71:
ldr r10,[r5,r9,lsl #2 ] @ load one factor
mul r10,r8,r10 @ multiply
str r10,[r5,r7,lsl #2] @ and store in the table
tst r10,#1 @ divsor odd ?
addne r11,#1
add r12,r10
add r7,r7,#1 @ and increment counter
add r9,r9,#1
cmp r9,r4
blt 71b
mov r4,r7
mov r7,#0
b 11f
9:
sub r9,r4,#1
mov r7,r4
91:
ldr r10,[r5,r9,lsl #2 ]
cmp r10,r8
subne r9,#1
bne 91b
sub r9,r4,r9
92:
ldr r10,[r5,r9,lsl #2 ]
mul r10,r8,r10
str r10,[r5,r7,lsl #2] @ and store in the table
tst r10,#1 @ divisor odd ?
addne r11,#1
add r12,r10
add r7,r7,#1 @ and increment counter
add r9,r9,#1
cmp r9,r4
blt 92b
mov r4,r7
b 11f
10:
mov r1,r3 @ current divisor = new divisor
cmp r1,r8 @ current divisor > new dividende ?
ble 2b @ no -> loop
/* end decomposition */
11:
mov r0,r4 @ return number of table items
mov r2,r12 @ return sum
mov r1,r11 @ return number of odd divisor
mov r3,#0
str r3,[r5,r4,lsl #2] @ store zéro in last table item
b 100f
 
98:
//ldr r0,iAdrszMessNbPrem
//bl affichageMess
mov r0,#1 @ return code
b 100f
99:
ldr r0,iAdrszMessError
bl affichageMess
mov r0,#-1 @ error code
b 100f
100:
pop {r3-r8,lr} @ restaur registers
bx lr
iAdrszMessNbPrem: .int szMessNbPrem
/***************************************************/
/* check if a number is prime */
/***************************************************/
/* r0 contains the number */
/* r0 return 1 if prime 0 else */
@2147483647
@4294967297
@131071
isPrime:
push {r1-r6,lr} @ save registers
cmp r0,#0
beq 90f
cmp r0,#17
bhi 1f
cmp r0,#3
bls 80f @ for 1,2,3 return prime
cmp r0,#5
beq 80f @ for 5 return prime
cmp r0,#7
beq 80f @ for 7 return prime
cmp r0,#11
beq 80f @ for 11 return prime
cmp r0,#13
beq 80f @ for 13 return prime
cmp r0,#17
beq 80f @ for 17 return prime
1:
tst r0,#1 @ even ?
beq 90f @ yes -> not prime
mov r2,r0 @ save number
sub r1,r0,#1 @ exposant n - 1
mov r0,#3 @ base
bl moduloPuR32 @ compute base power n - 1 modulo n
cmp r0,#1
bne 90f @ if <> 1 -> not prime
mov r0,#5
bl moduloPuR32
cmp r0,#1
bne 90f
mov r0,#7
bl moduloPuR32
cmp r0,#1
bne 90f
mov r0,#11
bl moduloPuR32
cmp r0,#1
bne 90f
mov r0,#13
bl moduloPuR32
cmp r0,#1
bne 90f
mov r0,#17
bl moduloPuR32
cmp r0,#1
bne 90f
80:
mov r0,#1 @ is prime
b 100f
90:
mov r0,#0 @ no prime
100: @ fin standard de la fonction
pop {r1-r6,lr} @ restaur des registres
bx lr @ retour de la fonction en utilisant lr
/********************************************************/
/* Calcul modulo de b puissance e modulo m */
/* Exemple 4 puissance 13 modulo 497 = 445 */
/* */
/********************************************************/
/* r0 nombre */
/* r1 exposant */
/* r2 modulo */
/* r0 return result */
moduloPuR32:
push {r1-r7,lr} @ save registers
cmp r0,#0 @ verif <> zero
beq 100f
cmp r2,#0 @ verif <> zero
beq 100f @ TODO: vérifier les cas d erreur
1:
mov r4,r2 @ save modulo
mov r5,r1 @ save exposant
mov r6,r0 @ save base
mov r3,#1 @ start result
 
mov r1,#0 @ division de r0,r1 par r2
bl division32R
mov r6,r2 @ base <- remainder
2:
tst r5,#1 @ exposant even or odd
beq 3f
umull r0,r1,r6,r3
mov r2,r4
bl division32R
mov r3,r2 @ result <- remainder
3:
umull r0,r1,r6,r6
mov r2,r4
bl division32R
mov r6,r2 @ base <- remainder
 
lsr r5,#1 @ left shift 1 bit
cmp r5,#0 @ end ?
bne 2b
mov r0,r3
100: @ fin standard de la fonction
pop {r1-r7,lr} @ restaur des registres
bx lr @ retour de la fonction en utilisant lr
 
/***************************************************/
/* division number 64 bits in 2 registers by number 32 bits */
/***************************************************/
/* r0 contains lower part dividende */
/* r1 contains upper part dividende */
/* r2 contains divisor */
/* r0 return lower part quotient */
/* r1 return upper part quotient */
/* r2 return remainder */
division32R:
push {r3-r9,lr} @ save registers
mov r6,#0 @ init upper upper part remainder !!
mov r7,r1 @ init upper part remainder with upper part dividende
mov r8,r0 @ init lower part remainder with lower part dividende
mov r9,#0 @ upper part quotient
mov r4,#0 @ lower part quotient
mov r5,#32 @ bits number
1: @ begin loop
lsl r6,#1 @ shift upper upper part remainder
lsls r7,#1 @ shift upper part remainder
orrcs r6,#1
lsls r8,#1 @ shift lower part remainder
orrcs r7,#1
lsls r4,#1 @ shift lower part quotient
lsl r9,#1 @ shift upper part quotient
orrcs r9,#1
@ divisor sustract upper part remainder
subs r7,r2
sbcs r6,#0 @ and substract carry
bmi 2f @ négative ?
@ positive or equal
orr r4,#1 @ 1 -> right bit quotient
b 3f
2: @ negative
orr r4,#0 @ 0 -> right bit quotient
adds r7,r2 @ and restaur remainder
adc r6,#0
3:
subs r5,#1 @ decrement bit size
bgt 1b @ end ?
mov r0,r4 @ lower part quotient
mov r1,r9 @ upper part quotient
mov r2,r7 @ remainder
100: @ function end
pop {r3-r9,lr} @ restaur registers
bx lr
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
<pre>
Program start
The first 25 abundant odd numbers are:
Number : 945 sum : 975
Number : 1575 sum : 1649
Number : 2205 sum : 2241
Number : 2835 sum : 2973
Number : 3465 sum : 4023
Number : 4095 sum : 4641
Number : 4725 sum : 5195
Number : 5355 sum : 5877
Number : 5775 sum : 6129
Number : 5985 sum : 6495
Number : 6435 sum : 6669
Number : 6615 sum : 7065
Number : 6825 sum : 7063
Number : 7245 sum : 7731
Number : 7425 sum : 7455
Number : 7875 sum : 8349
Number : 8085 sum : 8331
Number : 8415 sum : 8433
Number : 8505 sum : 8967
Number : 8925 sum : 8931
Number : 9135 sum : 9585
Number : 9555 sum : 9597
Number : 9765 sum : 10203
Number : 10395 sum : 12645
Number : 11025 sum : 11946
The 1000 odd abundant number :
Number : 492975 sum : 519361
First odd abundant number > 1000000000 :
Number : 1000000575 sum : 1083561009
Program normal end.
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">abundant?: function [n]-> (2*n) < sum factors n
 
print "the first 25 abundant odd numbers:"
[i, found]: @[new 1, new 0]
while [found<25][
if abundant? i [
inc 'found
print [i "=> sum:" sum factors i]
]
'i + 2
]
 
[i, found]: @[new 1, new 0]
while [found<1000][
if abundant? i [
inc 'found
]
'i + 2
]
print ["the 1000th abundant odd number:" i-2 "=> sum:" sum factors i-2]
 
i: new 1 + 10^9
while ø [
if abundant? i [
print ["the first abundant odd number greater than one billion (10^9):" i "=> sum:" sum factors i]
break
]
'i + 2
]</syntaxhighlight>
 
{{out}}
 
<pre>the first 25 abundant odd numbers:
945 => sum: 1920
1575 => sum: 3224
2205 => sum: 4446
2835 => sum: 5808
3465 => sum: 7488
4095 => sum: 8736
4725 => sum: 9920
5355 => sum: 11232
5775 => sum: 11904
5985 => sum: 12480
6435 => sum: 13104
6615 => sum: 13680
6825 => sum: 13888
7245 => sum: 14976
7425 => sum: 14880
7875 => sum: 16224
8085 => sum: 16416
8415 => sum: 16848
8505 => sum: 17472
8925 => sum: 17856
9135 => sum: 18720
9555 => sum: 19152
9765 => sum: 19968
10395 => sum: 23040
11025 => sum: 22971
the 1000th abundant odd number: 492975 => sum: 1012336
the first abundant odd number greater than one billion (10^9): 1000000575 => sum: 2083561584</pre>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">Abundant(num){
sum := 0, str := ""
for n, bool in proper_divisors(num)
sum += n, str .= (str?"+":"") n
return sum > num ? str " = " sum : 0
}
proper_divisors(n) {
Array := []
if n = 1
return Array
Array[1] := true
x := Floor(Sqrt(n))
loop, % x+1
if !Mod(n, i:=A_Index+1) && (floor(n/i) < n)
Array[floor(n/i)] := true
Loop % n/x
if !Mod(n, i:=A_Index+1) && (i < n)
Array[i] := true
return Array
}</syntaxhighlight>
Examples:<syntaxhighlight lang="autohotkey">output := "First 25 abundant odd numbers:`n"
while (count<1000)
{
oddNum := 2*A_Index-1
if (str := Abundant(oddNum))
{
count++
if (count<=25)
output .= oddNum " " str "`n"
if (count = 1000)
output .= "`nOne thousandth abundant odd number:`n" oddNum " " str "`n"
}
}
count := 0
while !count
{
num := 2*A_Index -1 + 1000000000
if (str := Abundant(num))
{
count++
output .= "`nFirst abundant odd number greater than one billion:`n" num " " str "`n"
}
}
MsgBox % output
return</syntaxhighlight>
{{out}}
<pre>First 25 abundant odd numbers:
945 1+3+5+7+9+15+21+27+35+45+63+105+135+189+315 = 975
1575 1+3+5+7+9+15+21+25+35+45+63+75+105+175+225+315+525 = 1649
2205 1+3+5+7+9+15+21+35+45+49+63+105+147+245+315+441+735 = 2241
2835 1+3+5+7+9+15+21+27+35+45+63+81+105+135+189+315+405+567+945 = 2973
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
 
One thousandth abundant odd number:
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
 
First abundant odd number greater than one billion:
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
</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f ABUNDANT_ODD_NUMBERS.AWK
# converted from C
BEGIN {
print(" index number sum")
fmt = "%8s %10d %10d\n"
n = 1
for (c=0; c<25; n+=2) {
if (n < sum_proper_divisors(n)) {
printf(fmt,++c,n,sum)
}
}
for (; c<1000; n+=2) {
if (n < sum_proper_divisors(n)) {
c++
}
}
printf(fmt,1000,n-2,sum)
for (n=1000000001; ; n+=2) {
if (n < sum_proper_divisors(n)) {
break
}
}
printf(fmt,"1st > 1B",n,sum)
exit(0)
}
function sum_proper_divisors(n, j) {
sum = 1
for (i=3; i<sqrt(n)+1; i+=2) {
if (n % i == 0) {
sum += i + (i == (j = n / i) ? 0 : j)
}
}
return(sum)
}
</syntaxhighlight>
{{out}}
<pre>
index number 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
1st > 1B 1000000575 1083561009
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|Visual Basic .NET}}
<syntaxhighlight lang="basic256">
<lang BASIC256>
numimpar = 1
contar = 0
Line 374 ⟶ 2,014:
 
# Encontrar los números requeridos por la tarea:
 
# primeros 25 números abundantes impares
Print "Los primeros 25 números impares abundantes:"
Line 389 ⟶ 2,028:
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)
Line 409 ⟶ 2,047:
End While
End
</syntaxhighlight>
</lang>
 
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <math.h>
 
Line 435 ⟶ 2,072:
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>1: 945
Line 466 ⟶ 2,103:
The first abundant odd number above one billion is: 1000000575</pre>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">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}";
}</syntaxhighlight>
{{out}}
<pre>
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</pre>
 
=={{header|C++}}==
{{trans|Go}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <numeric>
Line 550 ⟶ 2,247:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 585 ⟶ 2,282:
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</pre>
 
=={{header|C sharpCLU}}==
<syntaxhighlight lang="clu">% Integer square root
<lang csharp>using static System.Console;
isqrt = proc (s: int) returns (int)
using System.Collections.Generic;
x0: int := s / 2
using System.Linq;
if x0 = 0 then
return(s)
else
x1: int := (x0 + s/x0) / 2
while x1 < x0 do
x0 := x1
x1 := (x0 + s/x0) / 2
end
return(x0)
end
end isqrt
 
% Calculate aliquot sum (for odd numbers only)
public static class AbundantOddNumbers
aliquot = proc (n: int) returns (int)
{
publicsum: staticint void:= Main() {1
for i: int in int$from_to_by(3, isqrt(n)+1, 2) do
WriteLine("First 25 abundant odd numbers:");
if n//i = 0 then
foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
WriteLine(); j: int := n / i
sum := sum + i
WriteLine($"The 1000th abundant odd number: {AbundantNumbers().ElementAt(999).Format()}");
WriteLine(); if i ~= j then
sum := sum + j
WriteLine($"First abundant odd number > 1b: {AbundantNumbers(1_000_000_001).First().Format()}");
} end
end
end
return(sum)
end aliquot
 
% Generate abundant odd numbers
static IEnumerable<(int n, int sum)> AbundantNumbers(int start = 3) =>
abundant_odd = iter (n: int) yields (int)
start.UpBy(2).Select(n => (n, sum: n.DivisorSum())).Where(x => x.sum > x.n);
while true do
if n < aliquot(n) then yield(n) end
n := n + 2
end
end abundant_odd
 
start_up = proc ()
static int DivisorSum(this int n) => 3.UpBy(2).TakeWhile(i => i * i <= n).Where(i => n % i == 0)
po: stream := stream$primary_output()
.Select(i => (a:i, b:n/i)).Sum(p => p.a == p.b ? p.a : p.a + p.b) + 1;
count: int := 0
for n: int in abundant_odd(1) do
count := count + 1
if count <= 25 cor count = 1000 then
stream$putl(po, int$unparse(count)
|| ":\t"
|| int$unparse(n)
|| "\taliquot: "
|| int$unparse(aliquot(n)))
if count = 1000 then break end
end
end
for n: int in abundant_odd(1000000001) do
stream$putl(po, "First above 1 billion: "
|| int$unparse(n)
|| " aliquot: "
|| int$unparse(aliquot(n)))
break
end
end start_up</syntaxhighlight>
{{out}}
<pre>1: 945 aliquot: 975
2: 1575 aliquot: 1649
3: 2205 aliquot: 2241
4: 2835 aliquot: 2973
5: 3465 aliquot: 4023
6: 4095 aliquot: 4641
7: 4725 aliquot: 5195
8: 5355 aliquot: 5877
9: 5775 aliquot: 6129
10: 5985 aliquot: 6495
11: 6435 aliquot: 6669
12: 6615 aliquot: 7065
13: 6825 aliquot: 7063
14: 7245 aliquot: 7731
15: 7425 aliquot: 7455
16: 7875 aliquot: 8349
17: 8085 aliquot: 8331
18: 8415 aliquot: 8433
19: 8505 aliquot: 8967
20: 8925 aliquot: 8931
21: 9135 aliquot: 9585
22: 9555 aliquot: 9597
23: 9765 aliquot: 10203
24: 10395 aliquot: 12645
25: 11025 aliquot: 11946
1000: 492975 aliquot: 519361
First above 1 billion: 1000000575 aliquot: 1083561009</pre>
 
=={{header|Common Lisp}}==
static IEnumerable<int> UpBy(this int n, int step) {
 
for (int i = n; ; i+=step) yield return i;
{{libheader|cl-annot}}
}
{{libheader|iterate}}
{{libheader|alexandria}}
 
Using the ''iterate'' library instead of the standard ''loop'' or ''do''.
 
<syntaxhighlight lang="lisp">;; * Loading the external libraries
(eval-when (:compile-toplevel :load-toplevel)
(ql:quickload '("cl-annot" "iterate" "alexandria")))
 
;; * The package definition
(defpackage :abundant-numbers
(:use :common-lisp :cl-annot :iterate)
(:import-from :alexandria :butlast))
(in-package :abundant-numbers)
 
(annot:enable-annot-syntax)
 
;; * Calculating the divisors
@inline
(defun divisors (n)
"Returns the divisors of N without sorting them."
@type fixnum n
(iter
(for divisor from (isqrt n) downto 1)
(for (values m rem) = (floor n divisor))
@type fixnum divisor
(when (zerop rem)
(collecting divisor into result)
(adjoining m into result))
(finally (return result))))
 
;; * Calculating the sum of divisors
(defun sum-of-divisors (n)
"Returns the sum of the proper divisors of N."
@type fixnum n
(reduce #'+ (butlast (divisors n))))
 
;; * Task 1
(time
(progn
(format t " Task 1~%")
(iter
(with i = 0)
(for n from 1 by 2)
(for sum-of-divisors = (sum-of-divisors n))
@type fixnum i n sum-of-divisors
(while (< i 25))
(when (< n sum-of-divisors)
(incf i)
(format t "~5D: ~6D ~7D~%" i n sum-of-divisors)))
 
;; * Task 2
(format t "~% Task 2~%")
(iter
(with i = 0)
(until (= i 1000))
(for n from 1 by 2)
(for sum-of-divisors = (sum-of-divisors n))
@type fixnum i n sum-of-divisors
(when (< n sum-of-divisors)
(incf i))
(finally (format t "~5D: ~6D ~7D~%" i n sum-of-divisors)))
 
;; * Task 3
(format t "~% Task 3~%")
(iter
(for n from (1+ (expt 10 9)) by 2)
(for sum-of-divisors = (sum-of-divisors n))
@type fixnum n sum-of-divisors
(until (< n sum-of-divisors))
(finally (format t "~D ~D~%~%" n sum-of-divisors)))))</syntaxhighlight>
 
static string Format(this (int n, int sum) pair) => $"{pair.n:N0} with sum {pair.sum:N0}";
}</lang>
{{out}}
<pre> Task 1
1: 945 975
First 25 abundant odd numbers:
2: 1575 1649
945 with sum 975
3: 2205 2241
1,575 with sum 1,649
4: 2835 2973
2,205 with sum 2,241
5: 3465 4023
2,835 with sum 2,973
6: 4095 4641
3,465 with sum 4,023
7: 4725 5195
4,095 with sum 4,641
8: 5355 5877
4,725 with sum 5,195
9: 5775 6129
5,355 with sum 5,877
10: 5985 6495
5,775 with sum 6,129
11: 6435 6669
5,985 with sum 6,495
12: 6615 7065
6,435 with sum 6,669
13: 6825 7063
6,615 with sum 7,065
14: 7245 7731
6,825 with sum 7,063
15: 7425 7455
7,245 with sum 7,731
16: 7875 8349
7,425 with sum 7,455
17: 8085 8331
7,875 with sum 8,349
18: 8415 8433
8,085 with sum 8,331
19: 8505 8967
8,415 with sum 8,433
20: 8925 8931
8,505 with sum 8,967
21: 9135 9585
8,925 with sum 8,931
22: 9555 9597
9,135 with sum 9,585
23: 9765 10203
9,555 with sum 9,597
24: 10395 12645
9,765 with sum 10,203
25: 11025 11946
10,395 with sum 12,645
11,025 with sum 11,946
 
Task 2
The 1000th abundant odd number: 492,975 with sum 519,361
1000: 492975 519361
 
Task 3
First abundant odd number > 1b: 1,000,000,575 with sum 1,083,561,009</pre>
1000000575 1083561009
 
Evaluation took:
1.022 seconds of real time
1.023269 seconds of total run time (1.021605 user, 0.001664 system)
[ Run times consist of 0.004 seconds GC time, and 1.020 seconds non-GC time. ]
100.10% CPU
1,422,837,844 processor cycles
54,820,848 bytes consed
</pre>
 
=={{header|D}}==
{{trans|C++}}
<langsyntaxhighlight lang="d">import std.stdio;
 
int[] divisors(int n) {
Line 706 ⟶ 2,552:
writeln("\nThe first abundant odd number above one billion is:");
abundantOdd(cast(int)(1e9 + 1), 0, 1, true);
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 743 ⟶ 2,589:
=={{header|Delphi}}==
{{trans|C}}
<langsyntaxhighlight lang="delphi">program AbundantOddNumbers;
 
{$APPTYPE CONSOLE}
Line 790 ⟶ 2,636:
 
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>1: 945
Line 819 ⟶ 2,665:
The one thousandth abundant odd number is: 492975
The first abundant odd number above one billion is: 1000000575
</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
 
<syntaxhighlight lang=easylang>
fastfunc sumdivs n .
sum = 1
i = 3
while i <= sqrt n
if n mod i = 0
sum += i
j = n / i
if i <> j
sum += j
.
.
i += 2
.
return sum
.
n = 1
numfmt 0 6
while cnt < 1000
sum = sumdivs n
if sum > n
cnt += 1
if cnt <= 25 or cnt = 1000
print cnt & " n: " & n & " sum: " & sum
.
.
n += 2
.
print ""
n = 1000000001
repeat
sum = sumdivs n
until sum > n
n += 2
.
print "1st > 1B: " & n & " sum: " & sum
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Abundant odd numbers. Nigel Galloway: August 1st., 2021
let fN g=Seq.initInfinite(int64>>(+)1L)|>Seq.takeWhile(fun n->n*n<=g)|>Seq.filter(fun n->g%n=0L)|>Seq.sumBy(fun n->let i=g/n in n+(if i=n then 0L else i))
let aon n=Seq.initInfinite(int64>>(*)2L>>(+)n)|>Seq.map(fun g->(g,fN g))|>Seq.filter(fun(n,g)->2L*n<g)
aon 1L|>Seq.take 25|>Seq.iter(fun(n,g)->printfn "The sum of the divisors of %d is %d" n g)
let n,g=aon 1L|>Seq.item 999 in printfn "\nThe 1000th abundant odd number is %d. The sum of it's divisors is %d" n g
let n,g=aon 1000000001L|>Seq.head in printfn "\nThe first abundant odd number greater than 1000000000 is %d. The sum of it's divisors is %d" n g
</syntaxhighlight>
{{out}}
<pre>
The sum of the divisors of 945 is 1920
The sum of the divisors of 1575 is 3224
The sum of the divisors of 2205 is 4446
The sum of the divisors of 2835 is 5808
The sum of the divisors of 3465 is 7488
The sum of the divisors of 4095 is 8736
The sum of the divisors of 4725 is 9920
The sum of the divisors of 5355 is 11232
The sum of the divisors of 5775 is 11904
The sum of the divisors of 5985 is 12480
The sum of the divisors of 6435 is 13104
The sum of the divisors of 6615 is 13680
The sum of the divisors of 6825 is 13888
The sum of the divisors of 7245 is 14976
The sum of the divisors of 7425 is 14880
The sum of the divisors of 7875 is 16224
The sum of the divisors of 8085 is 16416
The sum of the divisors of 8415 is 16848
The sum of the divisors of 8505 is 17472
The sum of the divisors of 8925 is 17856
The sum of the divisors of 9135 is 18720
The sum of the divisors of 9555 is 19152
The sum of the divisors of 9765 is 19968
The sum of the divisors of 10395 is 23040
The sum of the divisors of 11025 is 22971
 
The 1000th abundant odd number is 492975. The sum of it's divisors is 1012336
 
The first abundant odd number greater than 1000000000 is 1000000575. The sum of it's divisors is 2083561584
</pre>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
Line 833 ⟶ 2,762:
 
: first25 ( -- seq ) 25 1 abundant-odds-from ltake list>array ;
: 1,000th ( -- n ) 999 1 abundant-odds-from 999 [ cdr ] times carlnth ;
: first>10^9 ( -- n ) 1,000,000,001 abundant-odds-from car ;
 
Line 846 ⟶ 2,775:
[ print show nl ] 2tri@ ;
 
MAIN: abundant-odd-numbers-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 881 ⟶ 2,810:
First abundant odd number > one billion:
1,000,000,575 σ = 2,083,561,584
</pre>
 
=={{header|Fortran}}==
A basic direct solution. A more robust alternative would be to find
the prime factors and then use a formulaic approach.
<syntaxhighlight lang="fortran">
program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
implicit none
integer,parameter :: dp=kind(0.0d0)
character(len=*),parameter :: g='(*(g0,1x))'
integer :: j, icount
integer,allocatable :: list(:)
real(kind=dp) :: tally
 
write(*,*)'N sum'
icount=0 ! number of abundant odd numbers found
do j=1,huge(0)-1,2 ! loop through odd numbers for candidates
list=divisors(j) ! git list of divisors for current value
tally= sum([real(list,kind=dp)]) ! sum divisors
if(tally>2*j .and. iand(j,1) /= 0) then ! count an abundant odd number
icount=icount+1
select case(icount) ! if one of the values targeted print it
case(1:25,1000);write(*,g)icount,':',j!, list
end select
endif
if(icount.gt.1000)exit ! quit after last targeted value is found
enddo
 
do j=1000000001,huge(0),2
list=divisors(j)
tally= sum([real(list,kind=dp)])
if(tally>2*j .and. iand(j,1) /= 0) then
write(*,g)'First abundant odd number greater than one billion:',j
 
exit
endif
enddo
 
contains
 
function divisors(num) result (numbers)
!> brute force divisors
integer,intent(in) :: num
integer :: i
integer,allocatable :: numbers(:)
numbers=[integer :: ]
do i=1 , int(sqrt(real(num)))
if (mod(num , i) .eq. 0) numbers=[numbers, i,num/i]
enddo
end function divisors
 
end program main
</syntaxhighlight>
 
{{out}}
<pre>
N sum
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
1000 : 492975
First abundant odd number greater than one billion: 1000000575
</pre>
 
=={{header|FreeBASIC}}==
{{trans|Visual Basic .NET}}
<langsyntaxhighlight lang="freebasic">
Declare Function SumaDivisores(n As Integer) As Integer
 
Line 943 ⟶ 2,957:
Loop
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 978 ⟶ 2,992:
Primer número impar abundante > 1 000 000 000:
1000000575 suma divisoria adecuada: 1083561009
</pre>
 
=={{header|Frink}}==
Frink has efficient functions for factoring numbers that use trial division, wheel factoring, and Pollard rho factoring.
<syntaxhighlight lang="frink">isAbundantOdd[n] := sum[allFactors[n, true, false]] > n
 
n = 3
count = 0
 
println["The first 25 abundant odd numbers:"]
do
{
if isAbundantOdd[n]
{
println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]]
count = count + 1
}
 
n = n + 2
} while count < 25
 
 
println["\nThe thousandth abundant odd number:"]
n = 1
count = 0
do
{
n = n + 2
 
if isAbundantOdd[n]
count = count + 1
 
} until count == 1000
 
println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]]
 
println["\nThe first abundant odd number over 1 billion:"]
n = 10^9 + 1
count = 0
do
n = n + 2
until isAbundantOdd[n]
 
println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]]
</syntaxhighlight>
{{out}}
<pre>
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
 
The thousandth abundant odd number:
492975: proper divisor sum 519361
 
The first abundant odd number over 1 billion:
1000000575: proper divisor sum 1083561009
</pre>
 
=={{header|FutureBasic}}==
{{trans|C}}
FB's 'cln' keyword is used to enter a line of C or Objective-C code.
 
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn SumOfProperDivisors( n as NSUInteger ) as NSUinteger
NSUinteger sum = 1
 
cln for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
end fn = sum
 
NSUinteger n, c
cln for (n = 1, c = 0; c < 25; n += 2 ) if ( n < SumOfProperDivisors( n ) ) NSLog( @"%2lu: %lu", ++c, n );
 
cln for ( ; c < 1000; n += 2 ) if ( n < SumOfProperDivisors( n ) ) c ++;
NSLog( @"\nThe one thousandth abundant odd number is: %lu\n", n )
 
cln for ( n = 1000000001 ;; n += 2 ) if ( n < SumOfProperDivisors( n ) ) break;
NSLog( @"The first abundant odd number above one billion is: %lu\n", n )
 
HandleEvents
</syntaxhighlight>
 
The following is a 'pure' FB code version.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn SumOfProperDivisors( n as NSUInteger ) as NSUinteger
NSUinteger i, j, sum = 1
for i = 3 to sqr(n) step 2
if ( n mod i == 0 )
sum += i
j = n/i
if ( i != j )
sum += j
end if
end if
next
end fn = sum
 
NSUinteger n = 1, c
 
while ( c < 25 )
if ( n < fn SumOfProperDivisors( n ) )
NSLog( @"%2lu: %lu", c, n )
c++
end if
n += 2
wend
 
while ( c < 1000 )
if ( n < fn SumOfProperDivisors( n ) ) then c++
n += 2
wend
NSLog( @"\nThe one thousandth abundant odd number is: %lu\n", n )
 
n = 1000000001
while ( n >= fn SumOfProperDivisors( n ) )
n += 2
wend
NSLog( @"The first abundant odd number above one billion is: %lu\n", n )
 
HandleEvents
</syntaxhighlight>
 
{{out}}
<pre>
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
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,053 ⟶ 3,249:
fmt.Println("\nThe first abundant odd number above one billion is:")
abundantOdd(1e9+1, 0, 1, true)
}</langsyntaxhighlight>
 
{{out}}
Line 1,093 ⟶ 3,289:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class Abundant {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
Line 1,157 ⟶ 3,353:
abundantOdd((int) (1e9 + 1), 0, 1, true)
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 1,193 ⟶ 3,389:
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">import Data.List (nub)
 
divisorSum :: Integral a => a -> a
Line 1,221 ⟶ 3,417:
printAbundant $ oddAbundants 1 !! 1000
putStrLn "The first odd abundant number above 1000000000 is:"
printAbundant . head . oddAbundants $ 10 ^ 9</langsyntaxhighlight>
 
{{out}}
Line 1,255 ⟶ 3,451:
1000000575 with 2083561584 as the sum of all proper divisors.</pre>
 
Or, alternativelyimporting Data.Numbers.Primes (and already a littlesignificantly faster):
<langsyntaxhighlight lang="haskell">import Data.BoolList (boolgroup, sort)
import Data.Numbers.Primes
 
abundantTuple :: Int -> [(Int, Int)]
abundantTuple n =
let x = divisorSum n
in bool [] [(n, x)] (| n < x)]
 
divisorSum :: Int -> Int
divisorSum n = sum . init . divisors
 
sum lows +
divisors :: Int -> [Int]
sum (drop (bool 0 1 (iRoot * iRoot == n)) (reverse (quot n <$> tail lows)))
divisors =
where
foldr
iRoot = floor (sqrt $ fromIntegral n)
lows = filter(flip ((== 0<*>) . remfmap n(*)) [1 .. iRoot]scanl (*) 1)
[1]
. group
. primeFactors
 
main :: IO ()
main = do
putStrLn
putStrLn "First 25 abundant odd numbers with their divisor sums:"
"First 25 abundant odd numbers with their divisor sums:"
mapM_ print $ take 25 ([1,3 ..] >>= abundantTuple)
mapM_ print $ take 25 ([1, 3 ..] >>= abundantTuple)
--
putStrLn
putStrLn "\n1000th odd abundant number with its divisor sum:"
"\n1000th odd abundant number with its divisor sum:"
print $ ([1,3 ..] >>= abundantTuple) !! 999
print $ ([1, 3 ..] >>= abundantTuple) !! 999
--
putStrLn
putStrLn "\nFirst odd abundant number over 10^9, with its divisor sum:"
( "\nFirst odd abundant number over 10^9, "
<> "with its divisor sum:"
)
let billion = 10 ^ 9 :: Int
print $
print $ head ([1 + billion,3 + billion ..] >>= abundantTuple)</lang>
head
( [1 + billion, 3 + billion ..]
>>= abundantTuple
)</syntaxhighlight>
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
Line 1,358 ⟶ 3,567:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.util.ArrayList;
import java.util.List;
 
Line 1,403 ⟶ 3,612:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,445 ⟶ 3,654:
Composing reusable functions and generators:
{{Trans|Python}}
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
const main = () => {
Line 1,655 ⟶ 3,864:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>First 25 abundant odd numbers, with their divisor sums:
Line 1,689 ⟶ 3,898:
First abundant odd number above 10^9, with divisor sum:
(1000000575,1083561009)</pre>
 
=={{header|jq}}==
<syntaxhighlight lang="jq">
# The factors, unsorted
def factors:
. as $num
| reduce range(1; 1 + sqrt|floor) as $i
([];
if ($num % $i) == 0 then
($num / $i) as $r
| if $i == $r then . + [$i] else . + [$i, $r] end
else .
end) ;
 
def abundant_odd_numbers:
range(1; infinite; 2)
| (factors | add) as $sum
| select($sum > 2*.)
| [., $sum] ;</syntaxhighlight>
 
Computing the first abundant number greater than 10^9 is presently impractical using jq, but for the other tasks:
<syntaxhighlight lang="text">( ["n", "sum of divisors"],
limit(25; abundant_odd_numbers)),
[],
(["The 1000th abundant odd number and corresponding sum of divisors:"]
+ nth(999; abundant_odd_numbers))
| @tsv
</syntaxhighlight>
{{out}}
<pre>
n sum of divisors
945 1920
1575 3224
2205 4446
2835 5808
3465 7488
4095 8736
4725 9920
5355 11232
5775 11904
5985 12480
6435 13104
6615 13680
6825 13888
7245 14976
7425 14880
7875 16224
8085 16416
8415 16848
8505 17472
8925 17856
9135 18720
9555 19152
9765 19968
10395 23040
11025 22971
 
The 1000th abundant odd number and corresponding sum of divisors: 492975 1012336
</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function propfact(n)
Line 1,699 ⟶ 3,967:
end
pop!(f)
sort(f)
end
 
Line 1,707 ⟶ 3,975:
function oddabundantsfrom(startingint, needed, nprint=0)
n = isodd(startingint) ? startingint : startingint + 1
count = 0one(n)
while count <= needed
if isabundant(n)
if nprint == 0
prettyprintfactors(n)
elseif nprint == count + 1
prettyprintfactors(n)
break
end
count += 1
Line 1,730 ⟶ 3,997:
println("The first abundant odd number greater than one billion:")
oddabundantsfrom(1000000000, 1)
</langsyntaxhighlight>{{out}}
<pre>
First 25 abundant odd numbers:
945 has proper divisors [1, 3, 95, 277, 59, 15, 4521, 13527, 735, 2145, 63, 189105, 35135, 105189, 315], these sum to 975.
1575 has proper divisors [1, 3, 9, 5, 157, 459, 2515, 7521, 22525, 735, 2145, 63, 3575, 105, 315175, 175225, 315, 525], these sum to 1649.
2205 has proper divisors [1, 3, 9, 5, 157, 459, 715, 21, 6335, 3545, 10549, 31563, 49105, 147, 441245, 245315, 441, 735], these sum to 2241.
2835 has proper divisors [1, 3, 95, 277, 819, 515, 1521, 4527, 13535, 40545, 763, 2181, 63105, 189135, 567189, 35315, 105405, 315567, 945], these sum to 2973.
3465 has proper divisors [1, 3, 95, 57, 159, 4511, 715, 21, 6333, 35, 10545, 31555, 1163, 3377, 99, 55105, 165, 495231, 77315, 231385, 693495, 385693, 1155], these sum to 4023.
4095 has proper divisors [1, 3, 95, 57, 159, 4513, 715, 21, 6335, 3539, 10545, 31563, 1365, 3991, 117105, 65117, 195, 585273, 91315, 273455, 819585, 455819, 1365], these sum to 4641.
4725 has proper divisors [1, 3, 95, 277, 59, 15, 4521, 13525, 2527, 7535, 22545, 67563, 775, 21105, 63135, 189175, 35189, 105225, 315, 945525, 175675, 525945, 1575], these sum to 5195.
5355 has proper divisors [1, 3, 95, 57, 159, 4515, 717, 21, 6335, 3545, 10551, 31563, 1785, 51105, 153119, 85153, 255, 765315, 119357, 357595, 1071765, 5951071, 1785], these sum to 5877.
5775 has proper divisors [1, 3, 5, 157, 2511, 75, 715, 21, 3525, 10533, 17535, 52555, 1175, 3377, 55105, 165, 275175, 825231, 77275, 231385, 385525, 825, 1155, 1925], these sum to 6129.
5985 has proper divisors [1, 3, 95, 57, 159, 4515, 719, 21, 6335, 3545, 10557, 31563, 1995, 57105, 171133, 95171, 285, 855315, 133399, 399665, 1197855, 6651197, 1995], these sum to 6495.
6435 has proper divisors [1, 3, 95, 59, 1511, 4513, 1115, 33, 9939, 5545, 16555, 49565, 1399, 39117, 117143, 65165, 195, 585429, 143495, 429585, 1287715, 7151287, 2145], these sum to 6669.
6615 has proper divisors [1, 3, 95, 277, 59, 15, 4521, 13527, 735, 2145, 6349, 18963, 35105, 105135, 315147, 945189, 49245, 147315, 441, 1323735, 245945, 7351323, 2205], these sum to 7065.
6825 has proper divisors [1, 3, 5, 157, 2513, 7515, 721, 2125, 35, 10539, 17565, 52575, 1391, 39105, 65175, 195, 325273, 975325, 91455, 273525, 455975, 1365, 2275], these sum to 7063.
7245 has proper divisors [1, 3, 9, 5, 157, 459, 715, 21, 6323, 35, 10545, 315, 2363, 69, 207105, 115, 345161, 1035207, 161315, 483345, 1449483, 805, 1035, 1449, 2415], these sum to 7731.
7425 has proper divisors [1, 3, 95, 279, 511, 15, 4525, 13527, 2533, 7545, 22555, 67575, 1199, 33135, 99165, 297225, 55275, 165297, 495, 1485675, 275825, 8251485, 2475], these sum to 7455.
7875 has proper divisors [1, 3, 9, 5, 157, 459, 2515, 7521, 22525, 12535, 37545, 112563, 775, 21105, 63125, 35175, 105225, 315, 175375, 525, 1575875, 8751125, 1575, 2625], these sum to 8349.
8085 has proper divisors [1, 3, 5, 15, 7, 2111, 3515, 10521, 4933, 14735, 24549, 73555, 1177, 33105, 55147, 165, 77231, 231245, 385, 1155539, 539735, 1155, 1617, 2695], these sum to 8331.
8415 has proper divisors [1, 3, 5, 9, 511, 15, 4517, 1133, 3345, 9951, 55, 16585, 49599, 17153, 51165, 153, 85187, 255, 765, 187495, 561, 1683765, 935, 1683, 2805], these sum to 8433.
8505 has proper divisors [1, 3, 95, 277, 819, 24315, 521, 1527, 4535, 13545, 40563, 121581, 7105, 21135, 63189, 189243, 567315, 1701405, 35567, 105945, 3151215, 9451701, 2835], these sum to 8967.
8925 has proper divisors [1, 3, 5, 157, 2515, 7517, 721, 2125, 35, 10551, 17575, 52585, 17105, 51119, 85175, 255, 425357, 1275425, 119525, 357595, 5951275, 1785, 2975], these sum to 8931.
9135 has proper divisors [1, 3, 9, 5, 157, 459, 715, 21, 6329, 35, 10545, 315, 2963, 87, 261105, 145, 435203, 1305261, 203315, 609435, 1827609, 1015, 1305, 1827, 3045], these sum to 9585.
9555 has proper divisors [1, 3, 5, 157, 713, 15, 21, 35, 10539, 49, 14765, 24591, 735105, 13, 39, 65147, 195, 91245, 273, 455, 1365637, 637735, 1365, 1911, 3185], these sum to 9597.
9765 has proper divisors [1, 3, 9, 5, 157, 459, 715, 21, 6331, 35, 10545, 315, 3163, 93, 279105, 155, 465217, 1395279, 217315, 651465, 1953651, 1085, 1395, 1953, 3255], these sum to 10203.
10395 has proper divisors [1, 3, 9, 27, 5, 157, 459, 13511, 715, 21, 6327, 18933, 35, 10545, 31555, 94563, 11, 3377, 99, 297105, 55135, 165, 495189, 1485231, 77297, 231315, 693385, 2079495, 385693, 945, 1155, 1485, 2079, 3465], these sum to 12645.
11025 has proper divisors [1, 3, 95, 57, 9, 15, 4521, 25, 7535, 22545, 7, 2149, 63, 3575, 105, 315147, 175, 525225, 1575245, 49, 147315, 441, 245525, 735, 22051225, 12251575, 2205, 3675], these sum to 11946.
The thousandth abundant odd number:
492975 has proper divisors [1, 3, 9, 5, 157, 459, 2515, 7521, 22525, 735, 2145, 63, 3575, 105, 315175, 175225, 525313, 1575315, 313525, 939, 28171565, 15651575, 46952191, 140852817, 78254695, 234756573, 704257825, 219110955, 657314085, 19719, 1095523475, 32865, 9859554775, 5477570425, 98595, 164325], these sum to 519361.
The first abundant odd number greater than one billion:
1000000575 has proper divisors [1, 3, 95, 57, 9, 15, 4521, 25, 7535, 22545, 7, 2149, 63, 3575, 105, 315147, 175, 525225, 1575245, 49, 147315, 441, 245525, 735, 22051225, 12251575, 2205, 3675, 11025, 90703, 272109, 816327453515, 453515634921, 816327, 1360545, 40816351904763, 2267575, 68027253174605, 204081754081635, 634921, 19047634444447, 5714289, 31746056802725, 9523815, 2857144513333341, 15873025, 4761907520408175, 14285722522222235, 4444447, 1333334128571445, 40000023, 2222223547619075, 66666705, 200000115111111175, 111111175142857225, 200000115, 333333525], these sum to 1083561009.</pre>
</pre>
 
=={{header|Kotlin}}==
{{trans|D}}
<langsyntaxhighlight lang="scala">fun divisors(n: Int): List<Int> {
val divs = mutableListOf(1)
val divs2 = mutableListOf<Int>()
Line 1,823 ⟶ 4,089:
println("\nThe first abundant odd number above one billion is:")
abundantOdd((1e9 + 1).toInt(), 0, 1, true)
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 1,857 ⟶ 4,123:
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</pre>
 
=={{header|Lobster}}==
{{trans|C}}
<syntaxhighlight lang="lobster">
// Note that the following function is for odd numbers only
// Use "for (unsigned i = 2; i*i <= n; i++)" for even and odd numbers
 
def sum_proper_divisors_of_odd(n: int) -> int:
var sum = 1
var i = 3
let limit = sqrt(n) + 1
while i < limit:
if n % i == 0:
sum += i
let j = n / i
if i != j:
sum += j
i += 2
return sum
 
def abundant_odd_numbers():
var n = 1
var c = 0
print "index: number proper_sum"
while c < 25:
let s = sum_proper_divisors_of_odd(n)
if n < s:
c += 1
print concat_string([string(c), ": ", string(n), ", ", string(s)], "")
n += 2
var s = 1
while c < 1000:
s = sum_proper_divisors_of_odd(n)
if n < s:
c += 1
n += 2
print concat_string(["1000: ", string(n), ", ", string(s)], "")
n = 999999999
while n >= s:
n += 2
s = sum_proper_divisors_of_odd(n)
print concat_string(["The first abundant odd number above one billion is: ", string(n), ", ", string(s)], "")
 
 
abundant_odd_numbers()
</syntaxhighlight>
{{out}}
<pre>
index: number proper_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: 492977, 519361
The first abundant odd number above one billion is: 1000000575, 1083561009
</pre>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">-- Return the sum of the proper divisors of x
function sumDivs (x)
local sum, sqr = 1, math.sqrt(x)
Line 1,895 ⟶ 4,238:
for k, v in pairs(oddAbundants("First", 25)) do showResult(k, v) end
showResult("1000", oddAbundants("Nth", 1000))
showResult("Above 1e6", oddAbundants("Above", 1e6))</langsyntaxhighlight>
{{out}}
<pre>1: the proper divisors of 945 sum to 975
Line 1,924 ⟶ 4,267:
1000: the proper divisors of 492975 sum to 519361
Above 1e6: the proper divisors of 1000125 sum to 1076547</pre>
 
=={{header|MAD}}==
 
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(ND)
ENTRY TO ODDSUM.
SUM = 1
SQN = SQRT.(ND)
THROUGH CHECK, FOR CN=3, 2, CN.G.SQN
TM = ND/CN
WHENEVER TM*CN.E.ND
SUM = SUM + CN
WHENEVER TM.NE.CN, SUM = SUM + TM
CHECK END OF CONDITIONAL
FUNCTION RETURN SUM
END OF FUNCTION
SEEN = 0
NUM = 1
THROUGH SHOW, FOR NUM=1, 2, SEEN.G.1000
WHENEVER NUM.L.ODDSUM.(NUM)
SEEN = SEEN + 1
WHENEVER SEEN.LE.25 .OR. SEEN.E.1000,
0 PRINT FORMAT OUTFMT,SEEN,NUM,ODDSUM.(NUM)
SHOW END OF CONDITIONAL
BILION THROUGH BILION, FOR NUM=NUM, 2,
0 NUM.G.1000000000 .AND. NUM.L.ODDSUM.(NUM)
PRINT FORMAT HUGENO,NUM,ODDSUM.(NUM)
VECTOR VALUES OUTFMT =
0 $4HNO. ,I4,S1,3HIS ,I6,S1,7HDIVSUM ,I6*$
VECTOR VALUES HUGENO =
0 $25HFIRST ABOVE 1 BILLION IS ,I10,S1,7HDIVSUM ,I10*$
END OF PROGRAM</syntaxhighlight>
 
{{out}}
 
<pre>NO. 1 IS 945 DIVSUM 975
NO. 2 IS 1575 DIVSUM 1649
NO. 3 IS 2205 DIVSUM 2241
NO. 4 IS 2835 DIVSUM 2973
NO. 5 IS 3465 DIVSUM 4023
NO. 6 IS 4095 DIVSUM 4641
NO. 7 IS 4725 DIVSUM 5195
NO. 8 IS 5355 DIVSUM 5877
NO. 9 IS 5775 DIVSUM 6129
NO. 10 IS 5985 DIVSUM 6495
NO. 11 IS 6435 DIVSUM 6669
NO. 12 IS 6615 DIVSUM 7065
NO. 13 IS 6825 DIVSUM 7063
NO. 14 IS 7245 DIVSUM 7731
NO. 15 IS 7425 DIVSUM 7455
NO. 16 IS 7875 DIVSUM 8349
NO. 17 IS 8085 DIVSUM 8331
NO. 18 IS 8415 DIVSUM 8433
NO. 19 IS 8505 DIVSUM 8967
NO. 20 IS 8925 DIVSUM 8931
NO. 21 IS 9135 DIVSUM 9585
NO. 22 IS 9555 DIVSUM 9597
NO. 23 IS 9765 DIVSUM 10203
NO. 24 IS 10395 DIVSUM 12645
NO. 25 IS 11025 DIVSUM 11946
NO. 1000 IS 492975 DIVSUM 519361
FIRST ABOVE 1 BILLION IS 1000000575 DIVSUM 1083561009</pre>
 
 
 
=={{header|Maple}}==
 
<syntaxhighlight lang="maple">
with(NumberTheory):
 
# divisorSum returns the sum of the divisors of x not including x
divisorSum := proc(x::integer)
return SumOfDivisors(x) - x;
end proc:
 
 
# abundantNumber returns true if x is an abundant number and false otherwise
abundantNumber := proc(x::integer)
if (SumOfDivisors(x) > 2*x) then return true
else return false end if;
end proc:
 
count := 0:
number := 1:
 
cat("First 25 abundant odd numbers");
 
while count < 25 do
if (abundantNumber(number)) then
count += 1:
print(cat(count, ": ", number, " sum of divisors ", SumOfDivisors(number), " sum of proper divisors ", divisorSum(number)));
else end if;
number += 2:
end:
 
while (count < 1000) do
if (abundantNumber(number)) then
count += 1:
else end if:
number += 2:
end:
 
cat("The 1000th odd abundant number is ", number - 2, ", its sum of divisors is ", SumOfDivisors(number - 2), ", and its sum of proper divisors is ", divisorSum(number - 2));
 
for number from 10^9 + 1 by 2 to infinity while not abundantNumber(number) do end:
 
cat("First abundant odd number > 10^9 is ", number, ", its sum of divisors is ", SumOfDivisors(number), ", and its sum of proper divisors is ",divisorSum(number));
 
</syntaxhighlight>
{{out}}<pre>
"First 25 abundant odd numbers"
 
1: 945 sum of divisors 1920 sum of proper divisors 975
 
2: 1575 sum of divisors 3224 sum of proper divisors 1649
 
3: 2205 sum of divisors 4446 sum of proper divisors 2241
 
4: 2835 sum of divisors 5808 sum of proper divisors 2973
 
5: 3465 sum of divisors 7488 sum of proper divisors 4023
 
6: 4095 sum of divisors 8736 sum of proper divisors 4641
 
7: 4725 sum of divisors 9920 sum of proper divisors 5195
 
8: 5355 sum of divisors 11232 sum of proper divisors 5877
 
9: 5775 sum of divisors 11904 sum of proper divisors 6129
 
10: 5985 sum of divisors 12480 sum of proper divisors 6495
 
11: 6435 sum of divisors 13104 sum of proper divisors 6669
 
12: 6615 sum of divisors 13680 sum of proper divisors 7065
 
13: 6825 sum of divisors 13888 sum of proper divisors 7063
 
14: 7245 sum of divisors 14976 sum of proper divisors 7731
 
15: 7425 sum of divisors 14880 sum of proper divisors 7455
 
16: 7875 sum of divisors 16224 sum of proper divisors 8349
 
17: 8085 sum of divisors 16416 sum of proper divisors 8331
 
18: 8415 sum of divisors 16848 sum of proper divisors 8433
 
19: 8505 sum of divisors 17472 sum of proper divisors 8967
 
20: 8925 sum of divisors 17856 sum of proper divisors 8931
 
21: 9135 sum of divisors 18720 sum of proper divisors 9585
 
22: 9555 sum of divisors 19152 sum of proper divisors 9597
 
23: 9765 sum of divisors 19968 sum of proper divisors 10203
 
24: 10395 sum of divisors 23040 sum of proper divisors 12645
 
25: 11025 sum of divisors 22971 sum of proper divisors 11946
 
"The 1000th odd abundant number is 492975, its sum of divisors is 1012336, and its sum of proper divisors is 519361"
 
"First abundant odd number > 10^9 is 1000000575, its sum of divisors is 2083561584, and its sum of proper divisors is 1083561009"
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
 
<syntaxhighlight lang="mathematica">ClearAll[AbundantQ]
AbundantQ[n_] := TrueQ[Greater[Total @ Most @ Divisors @ n, n]]
res = {};
i = 1;
While[Length[res] < 25,
If[AbundantQ[i],
AppendTo[res, {i, Total @ Most @ Divisors @ i}];
];
i += 2;
];
res
 
res = {};
i = 1;
While[Length[res] < 1000,
If[AbundantQ[i],
AppendTo[res, {i, Total @ Most @ Divisors @ i}];
];
i += 2;
];
res[[-1]]
 
res = {};
i = 1000000001;
While[Length[res] < 1,
If[AbundantQ[i],
AppendTo[res, {i, Total @ Most @ Divisors @ i}];
];
i += 2;
];
res</syntaxhighlight>
{{out}}
<pre>{{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}}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">block([k: 0, n: 1, l: []],
while k < 25 do (
n: n+2,
if divsum(n,-1) > 2 then (
k: k+1,
l: append(l, [[n,divsum(n)]])
)
),
return(l)
);</syntaxhighlight>
{{out}}
<pre>[[945,1920],[1575,3224],[2205,4446],[2835,5808],[3465,7488],[4095,8736],[4725,9920],[5355,11232],[5775,11904],[5985,12480],[6435,13104],[6615,13680],[6825,13888],[7245,14976],[7425,14880],[7875,16224],[8085,16416],[8415,16848],[8505,17472],[8925,17856],[9135,18720],[9555,19152],[9765,19968],[10395,23040],[11025,22971]]</pre>
 
<syntaxhighlight lang="maxima">block([k: 0, n: 1],
while k < 1000 do (
n: n+2,
if divsum(n,1) > 2*n then k: k+1
),
return([n,divsum(n)])
);</syntaxhighlight>
{{out}}
<pre>[492975,1012336]</pre>
 
<syntaxhighlight lang="maxima">block([n: 5, l: [5], r: divsum(n,-1)],
while n < 10^8 do (
if not mod(n,3)=0 then (
s: divsum(n,-1),
if s > r then (r: s, l: append(l, [n]))
),
n: n+10
),
return(l)
);</syntaxhighlight>
{{out}}
<pre>[5,25,35,175,385,1925,5005,25025,85085,425425,1616615,8083075,37182145,56581525]</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
divisorSum = function(n)
ans = 0
i = 1
while i * i <= n
if n % i == 0 then
ans += i
j = floor(n / i)
if j != i then ans += j
end if
i += 1
end while
return ans
end function
 
cnt = 0
n = 1
while cnt < 25
sum = divisorSum(n) - n
if sum > n then
print n + ": " + sum
cnt += 1
end if
n += 2
end while
 
while true
sum = divisorSum(n) - n
if sum > n then
cnt += 1
if cnt == 1000 then break
end if
n += 2
end while
 
print "The 1000th abundant number is " + n + " with a proper divisor sum of " + sum
 
n = 1000000001
while true
sum = divisorSum(n) - n
if sum > n and n > 1000000000 then break
n += 2
end while
 
print "The first abundant number > 1b is " + n + " with a proper divisor sum of " + sum
</syntaxhighlight>
{{out}}
<pre>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
The 1000th abundant number is 492975 with a proper divisor sum of 519361
The first abundant number > 1b is 1000000575 with a proper divisor sum of 1083561009
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">
from math import sqrt
import strformat
 
#---------------------------------------------------------------------------------------------------
 
proc sumProperDivisors(n: int): int =
## Compute the sum of proper divisors.
## "n" is supposed to be odd.
result = 1
for d in countup(3, sqrt(n.toFloat).int, 2):
if n mod d == 0:
inc result, d
if n div d != d:
inc result, n div d
 
#---------------------------------------------------------------------------------------------------
 
iterator oddAbundant(start: int): tuple[n, s: int] =
## Yield the odd abundant numbers and the sum of their proper
## divisors greater or equal to "start".
var n = start + (start and 1 xor 1) # Start with an odd number.
while true:
let s = n.sumProperDivisors()
if s > n:
yield (n, s)
inc n, 2
 
#---------------------------------------------------------------------------------------------------
 
echo "List of 25 first odd abundant numbers."
echo "Rank Number Proper divisors sum"
echo "---- ----- -------------------"
var rank = 0
for (n, s) in oddAbundant(1):
inc rank
echo fmt"{rank:2}: {n:5} {s:5}"
if rank == 25:
break
 
echo ""
rank = 0
for (n, s) in oddAbundant(1):
inc rank
if rank == 1000:
echo fmt"The 1000th odd abundant number is {n}."
echo fmt"The sum of its proper divisors is {s}."
break
 
echo ""
for (n, s) in oddAbundant(1_000_000_000):
if n > 1_000_000_000:
echo fmt"The first odd abundant number greater than 1000000000 is {n}."
echo fmt"The sum of its proper divisors is {s}."
break
</syntaxhighlight>
 
{{out}}
<pre>
List of 25 first odd abundant numbers.
Rank Number Proper divisors 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
 
The 1000th odd abundant number is 492975.
The sum of its proper divisors is 519361.
 
The first odd abundant number greater than 1000000000 is 1000000575.
The sum of its proper divisors is 1083561009.
</pre>
 
=={{header|Pari/GP}}==
<pre>
genit(brk1,brk2,brk3)={tcnt=0;
print("First 25 abundant odd numbers:");
forstep(n=1,999999999999999999,2,
if(tcnt==brk2&&n<brk3,next);
if(sigma(n)<=2*n,next);
tcnt+=1;
if(tcnt>brk1&&tcnt<brk2,next);
if(n>=brk3 && sigma(n)>2*n,print("The first odd abundant number greater than 1000000000 is ",n," with sigma = ",sigma(n) );break);
if(tcnt==brk2,print("The 1000th odd abundant number is ",n," with sigma = ",sigma(n) );next);
print(n," with sigma = ",sigma(n)));}
 
Output:
 
(11:14) gp > genit(25,1000,1000000000 )
First 25 abundant odd numbers:
945 with sigma = 1920
1575 with sigma = 3224
2205 with sigma = 4446
2835 with sigma = 5808
3465 with sigma = 7488
4095 with sigma = 8736
4725 with sigma = 9920
5355 with sigma = 11232
5775 with sigma = 11904
5985 with sigma = 12480
6435 with sigma = 13104
6615 with sigma = 13680
6825 with sigma = 13888
7245 with sigma = 14976
7425 with sigma = 14880
7875 with sigma = 16224
8085 with sigma = 16416
8415 with sigma = 16848
8505 with sigma = 17472
8925 with sigma = 17856
9135 with sigma = 18720
9555 with sigma = 19152
9765 with sigma = 19968
10395 with sigma = 23040
11025 with sigma = 22971
The 1000th odd abundant number is 492975 with sigma = 1012336
The first odd abundant number greater than 1000000000 is 1000000575 with sigma = 2083561584
(11:24) gp >
</pre>
 
=={{header|Pascal}}==
{{works with|Free Pascal}} {{works with|Delphi}}
<langsyntaxhighlight lang="pascal">
program AbundantOddNumbers;
{$IFDEF FPC}
Line 2,106 ⟶ 4,917:
Inc(N, 2);
WriteLn('The first abundant odd number above one billion is: ',OutNum(N));
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 2,145 ⟶ 4,956:
 
=={{header|Perl}}==
{{trans|Perl 6Raku}}
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,170 ⟶ 4,981:
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);</langsyntaxhighlight>
{{out}}
<pre style="height:20ex">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</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2019.03}}
 
<lang perl6>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;</lang>
{{out}}
<pre>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
Line 2,270 ⟶ 5,017:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function abundantOdd(integer n, done, lim, bool printAll)
<span style="color: #008080;">function</span> <span style="color: #000000;">abundantOdd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">done</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">printAll</span><span style="color: #0000FF;">)</span>
while done<lim do
<span style="color: #008080;">while</span> <span style="color: #000000;">done</span><span style="color: #0000FF;"><</span><span style="color: #000000;">lim</span> <span style="color: #008080;">do</span>
atom tot = sum(factors(n,-1))
<span style="color: #004080;">atom</span> <span style="color: #000000;">tot</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
if tot>n then
<span style="color: #008080;">if</span> <span style="color: #000000;">tot</span><span style="color: #0000FF;">></span><span style="color: #000000;">n</span> <span style="color: #008080;">then</span>
done += 1
<span style="color: #000000;">done</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
if printAll or done=lim then
<span style="color: #008080;">if</span> <span style="color: #000000;">printAll</span> <span style="color: #008080;">or</span> <span style="color: #000000;">done</span><span style="color: #0000FF;">=</span><span style="color: #000000;">lim</span> <span style="color: #008080;">then</span>
string ln = iff(printAll?sprintf("%2d. ",done):"")
<span style="color: #004080;">string</span> <span style="color: #000000;">ln</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">printAll</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%2d. "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">done</span><span style="color: #0000FF;">):</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
printf(1,"%s%,6d (proper sum:%,d)\n",{ln,n,tot})
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s%,6d (proper sum:%,d)\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">tot</span><span style="color: #0000FF;">})</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
n += 2
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">2</span>
end while
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
printf(1,"\n")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
return n
<span style="color: #008080;">return</span> <span style="color: #000000;">n</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
printf(1,"The first 25 abundant odd numbers are:\n")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 25 abundant odd numbers are:\n"</span><span style="color: #0000FF;">)</span>
integer n = abundantOdd(1, 0, 25, true)
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">abundantOdd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">true</span><span style="color: #0000FF;">)</span>
printf(1,"The one thousandth abundant odd number is:")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The one thousandth abundant odd number is:"</span><span style="color: #0000FF;">)</span>
{} = abundantOdd(n, 25, 1000, false)
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">abundantOdd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
printf(1,"The first abundant odd number above one billion is:")
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first abundant odd number above one billion is:"</span><span style="color: #0000FF;">)</span>
{} = abundantOdd(1e9+1, 0, 1, false)</lang>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">abundantOdd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1e9</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 2,326 ⟶ 5,075:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de accud (Var Key)
(if (assoc Key (val Var))
(con @ (inc (cdr @)))
Line 2,371 ⟶ 5,120:
'****
1000000575
(factor-sum 1000000575) ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 2,402 ⟶ 5,151:
**** 1000000575 1083561009
</pre>
 
=={{header|Processing}}==
<syntaxhighlight lang="processing">void setup() {
println("First 25 abundant odd numbers: ");
int abundant = 0;
int i = 1;
while (abundant < 25) {
int sigma_sum = sigma(i);
if (sigma_sum > 2 * i) {
abundant++;
println(i + " Sigma sum: " + sigma_sum);
}
i += 2;
}
println("Thousandth abundant odd number: ");
while (abundant < 1000) {
int sigma_sum = sigma(i);
if (sigma_sum > 2 * i) {
abundant++;
if (abundant == 1000) {
println(i + " Sigma sum: " + sigma_sum);
}
}
i += 2;
}
println("First abundant odd number greater than 10^9: ");
i = int(pow(10, 9)) + 1;
while (!(sigma(i) > 2 * i)) {
i += 2;
}
println(i + " Sigma sum: " + sigma(i));
}
 
int sigma(int n) {
int sum = 0;
for (int i = 1; i < sqrt(n); i++) {
if (n % i == 0) {
sum += i + n / i;
}
}
if (sqrt(n) % 1 == 0) {
sum += sqrt(n);
}
return sum;
}</syntaxhighlight>
{{out}}
<pre>First 25 abundant odd numbers:
945 Sigma sum: 1920
1575 Sigma sum: 3224
2205 Sigma sum: 4446
2835 Sigma sum: 5808
3465 Sigma sum: 7488
4095 Sigma sum: 8736
4725 Sigma sum: 9920
5355 Sigma sum: 11232
5775 Sigma sum: 11904
5985 Sigma sum: 12480
6435 Sigma sum: 13104
6615 Sigma sum: 13680
6825 Sigma sum: 13888
7245 Sigma sum: 14976
7425 Sigma sum: 14880
7875 Sigma sum: 16224
8085 Sigma sum: 16416
8415 Sigma sum: 16848
8505 Sigma sum: 17472
8925 Sigma sum: 17856
9135 Sigma sum: 18720
9555 Sigma sum: 19152
9765 Sigma sum: 19968
10395 Sigma sum: 23040
11025 Sigma sum: 22971
Thousandth abundant odd number:
492975 Sigma sum: 1012336
First abundant odd number greater than 10^9:
1000000575 Sigma sum: 2083561584</pre>
 
=={{header|PureBasic}}==
{{trans|C}}
<langsyntaxhighlight PureBasiclang="purebasic">NewList l_sum.i()
 
 
Line 2,474 ⟶ 5,299:
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre> 1: 945 -&gt; 975 = 1+3+5+7+9+15+21+27+35+45+63+105+135+189+315
Line 2,511 ⟶ 5,336:
===Procedural===
{{trans|Visual Basic .NET}}
<langsyntaxhighlight Pythonlang="python">#!/usr/bin/python
# Abundant odd numbers - Python
 
Line 2,556 ⟶ 5,381:
print ("\nFirst abundant odd number > 1 000 000 000:")
print (" ",oddNumber," proper divisor sum: ",dSum)
oddNumber += 2</langsyntaxhighlight>
{{out}}
<pre>
Line 2,594 ⟶ 5,419:
 
===Functional===
<langsyntaxhighlight lang="python">'''Odd abundant numbers'''
 
from math import sqrt
Line 2,694 ⟶ 5,519:
 
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
Line 2,728 ⟶ 5,553:
First odd abundant number over 10^9, with its divisor sum:
(1000000575, 1083561009)</pre>
 
=={{header|q}}==
<syntaxhighlight lang="q">s:{c where 0=x mod c:1+til x div 2} / proper divisors
sd:sum s@ / sum of proper divisors
abundant:{x<sd x}
Filter:{y where x each y}</syntaxhighlight>
Solution largely follows that for [[#J]], except the crucial definition of <code>s</code>.
The definition here is naïve. It suffices for the first two items in this task, but takes minutes to execute the third item on a 2018 Mac with 64GB memory.
{{out}}
<syntaxhighlight lang="q">q)count A:Filter[abundant] 1+2*til 260000 / a batch of abundant odd numbers; 1000+ is enough
1054
 
q)1 sd'\25#A / first 25 abundant odd numbers, and the sum of their divisors
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
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
 
q)1 sd\A 999 / 1000th abundant odd number and the sum of its divisors
492975 519361
 
q)1 sd\(not abundant@)(2+)/1000000000-1 / first abundant odd number above 1,000,000,000 and its divisors
1000000575 1083561009</syntaxhighlight>
References:
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/learn/pb/abundant-odds/ The Q Playbook: Abundant Odds – analysis]
 
=={{header|Quackery}}==
 
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
 
<syntaxhighlight lang="quackery"> [ 0 swap factors witheach + ] is sigmasum ( n --> n )
 
0 -1 [ 2 +
dup sigmasum
over 2 * over < iff
[ over echo sp
echo cr
dip 1+ ]
else drop
over 25 = until ]
2drop
cr
0 -1
[ 2 + dup sigmasum
over 2 * > if [ dip 1+ ]
over 1000 = until ]
dup echo sp sigmasum echo cr
drop
cr
999999999
[ 2 + dup sigmasum
over 2 * > until ]
dup echo sp sigmasum echo cr</syntaxhighlight>
 
{{out}}
 
<pre>945 1920
1575 3224
2205 4446
2835 5808
3465 7488
4095 8736
4725 9920
5355 11232
5775 11904
5985 12480
6435 13104
6615 13680
6825 13888
7245 14976
7425 14880
7875 16224
8085 16416
8415 16848
8505 17472
8925 17856
9135 18720
9555 19152
9765 19968
10395 23040
11025 22971
 
492975 1012336
 
1000000575 2083561584
</pre>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r"># Abundant Odd Numbers
 
find_div_sum <- function(x){
Line 2,770 ⟶ 5,680:
# Get the first after 1e9
cat("First odd abundant after 1e9 is")
get_n_abun(index = 1e9 + 1, total = 1, print_all = F)</langsyntaxhighlight>
 
{{Out}}
Line 2,808 ⟶ 5,718:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require math/number-theory
Line 2,821 ⟶ 5,731:
(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</langsyntaxhighlight>
 
{{out}}
Line 2,853 ⟶ 5,763:
'(1000000575 1083561009)
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2019.03}}
 
<syntaxhighlight lang="raku" line>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 = cache .&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;</syntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|REXX}}==
A wee bit of coding was added to add commas to numbers (because of the larger numbers) as well as alignment of the output.
 
The &nbsp; '''sigO''' &nbsp; function is a specialized version of the &nbsp; '''sigma''' &nbsp; function optimized just for &nbsp; ''odd'' &nbsp; numbers.
<langsyntaxhighlight lang="rexx">/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandthone-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 // */
@a= 'odd abundant number' /*variable for annotating the output. */
# n= 0 /*count of odd abundant numbers so far.*/
do j=3 by 2 until #n>=Nlow; $= sigO(j) /*get the sigma for an odd integer. */
d=sigO(j)
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
if d>j then Do #= # + 1 /*sigma = J ? Then ignore it. /*bump the counter for abundant odd #'s*/
n= n + 1 /*bump the counter for abundant odd n's*/
say rt(th(#)) @ 'is:'rt(commas(j), 8) rt("sigma=") rt(commas($), 9)
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
end /*j*/
End
end /*j*/
say
# n= 0 /*count of odd abundant numbers so far.*/
do j=3 by 2; $= sigO(j) /*get the sigma for an odd integer. */
d= sigO(j)
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
if d>j #= #then +do 1 /*sigma = J ? Then ignore it. /*bump the counter for abundant odd #'s*/
 
if #<Nuno then iterate /*Odd abundant# count<Nuno? Then skip.*/
n= n + 1 /*bump the counter for abundant odd n's*/
say rt(th(#)) @ 'is:'rt(commas(j), 8) rt("sigma=") rt(commas($), 9)
if n>=Nuno then do /*Odd abundantn count<Nuno? Then skip.*/
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
leave /*we're finished displaying NUNOth num.*/
end /*j*/End
End
end /*j*/
say
do j=1+Novr%2*2 by 2; $= sigO(j) /*get sigma for an odd integer > Novr. */
d= sigO(j)
if $<=j then iterate /*sigma ≤ J ? Then ignore it. */
if d>j say rt(th(1))then Do @ 'over' commas(Novr) "is: " commas(j) rt(' /*sigma =') commas($)J ? Then ignore it. */
say rt(th(1)) a 'over' commas(Novr) 'is: ' commas(j) rt('sigma=') commas(d)
leave /*we're finished displaying NOVRth num.*/
Leave /*we're finished displaying NOVRth num.*/
end /*j*/
End
exit /*stick a fork in it, we're all done. */
end /*j*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
exit
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)
commas:parse arg _; do c_=length(_)-3 to 1 by -3; _=insert(',',_,c_); end; return _
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
rt: procedure; parse arg n,len; if len=='' then len=20; return right(n,len)
/*──────────────────────────────────────────────────────────────────────────────────────*/
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
sigO: parse arg x; s= 1 /*sigma for odd integers. ___*/
/*--------------------------------------------------------------------------------------*/
do k=3 by 2 while k*k<x /*divide by all odd integers up to √ x */
sigO: parse arg x; if x//k==0 then s= s + k + x%k /*addsigma for odd integers. the two divisors to (sigma) sum. ___*/
s=1
end /*k*/ /* ___*/
do k=3 by 2 ifwhile k*k==<x then return s + k /*Was X a square? divide by all Ifodd so,integers addup to v x */
if x//k==0 then
return s /*return (sigma) sum of the divisors. */</lang>
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 v x */
return s /*return (sigma) sum of the divisors. */
</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 2,932 ⟶ 5,919:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
#Project: Anbundant odd numbers
 
Line 2,999 ⟶ 5,986:
see "" + index + ". " + string(n) + ": divisor sum: " +
see string(nArray[m]) + " = " + string(sum) + nl + nl
</syntaxhighlight>
</lang>
 
<pre>
Line 3,061 ⟶ 6,048:
done...
</pre>
 
=={{header|RPL}}==
{{works with|Hewlett-Packard|50g}}
≪ DUP DIVIS ∑LIST SWAP DUP + ≥
≫ '<span style="color:blue">ABUND?</span>' STO
≪ { } 1
'''DO'''
2 +
'''IF''' DUP <span style="color:blue">ABUND?</span> '''THEN'''
DUP "*2 <" + OVER DIVIS ∑LIST + ROT SWAP + SWAP '''END'''
'''UNTIL''' OVER SIZE 25 ≥ '''END''' DROP
≫ '<span style="color:blue">TASK1</span>' STO
≪ 0 1
'''DO'''
2 +
'''IF''' DUP <span style="color:blue">ABUND?</span> '''THEN''' SWAP 1 + SWAP '''END'''
'''UNTIL''' OVER 1000 ≥ '''END''' NIP
DUP "*2 <" + SWAP DIVIS ∑LIST +
≫ '<span style="color:blue">TASK2</span>' STO
≪ 1E9 1 -
'''DO'''
2 +
'''UNTIL''' DUP <span style="color:blue">ABUND?</span> '''END'''
DUP "*2 <" + SWAP DIVIS ∑LIST +
≫ '<span style="color:blue">TASK3</span>' STO
{{out}}
<pre>
3: { "945*2 < 1920" "1575*2 < 3224" "2205*2 < 4446" "2835*2 < 5808" "3465*2 < 7488" "4095*2 < 8736" "4725*2 < 9920" "5355*2 < 11232" "5775*2 < 11904" "5985*2 < 12480" "6435*2 < 13104" "6615*2 < 13680" "6825*2 < 13888" "7245*2 < 14976" "7425*2 < 14880" "7875*2 < 16224" "8085*2 < 16416" "8415*2 < 16848" "8505*2 < 17472" "8925*2 < 17856" "9135*2 < 18720" "9555*2 < 19152" "9765*2 < 19968" "10395*2 < 23040" "11025*2 < 22971" }
2: "492975*2 < 1012336"
1: "1000000575*2 < 2083561584"
</pre>
Abundant odd numbers are far from being abundant. It tooks 16 minutes to run TASK1 on an HP-50g calculator and 28 minutes to run TASK2 on an iOS emulator.
 
=={{header|Ruby}}==
proper_divisors method taken from http://rosettacode.org/wiki/Proper_divisors#Ruby
<langsyntaxhighlight lang="ruby">require "prime"
class Integer
Line 3,089 ⟶ 6,111:
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
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
{{trans|Go}}
<langsyntaxhighlight lang="rust">fn divisors(n: u64) -> Vec<u64> {
let mut divs = vec![1];
let mut divs2 = Vec::new();
Line 3,146 ⟶ 6,168:
println!("The first abundant odd number above one billion is:");
abundant_odd(1e9 as u64 + 1, 0, 1, true);
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 3,182 ⟶ 6,204:
=={{header|Scala}}==
{{trans|D}}
<langsyntaxhighlight lang="scala">import scala.collection.mutable.ListBuffer
 
object Abundant {
Line 3,241 ⟶ 6,263:
abundantOdd((1e9 + 1).intValue(), 0, 1, printOne = true)
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 25 abundant odd numbers are:
Line 3,277 ⟶ 6,299:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func is_abundant(n) {
n.sigma > 2*n
}
Line 3,303 ⟶ 6,325:
with(odd_abundants(1e9).first) {|n|
printf(sep + fstr, '***', n, n.sigma-n)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,337 ⟶ 6,359:
-------+-------------+-------------------
*** | 1000000575 | 1083561009
</pre>
 
=={{header|Smalltalk}}==
<syntaxhighlight lang="smalltalk">divisors :=
[:nr |
|divs|
 
divs := Set with:1.
"no need to check even factors; we are only looking for odd nrs"
3 to:(nr integerSqrt) by:2 do:[:d | nr % d = 0 ifTrue:[divs add:d; add:(nr / d)]].
divs.
].
 
isAbundant := [:nr | (divisors value:nr) sum > nr].
 
"from set of abdundant numbers >= minNr, print nMinPrint-th to nMaxPrint-th"
printNAbundant :=
[:minNr :nMinPrint :nMaxPrint |
|count divs|
 
count := 0.
minNr to:Infinity positive doWithExit:[:nr :exit |
(nr odd and:[isAbundant value:nr]) ifTrue:[
count := count + 1.
count >= nMinPrint ifTrue:[
divs := divisors value:nr.
Transcript
show:nr; show:' -> '; show:divs asArray sorted;
show:' sum = '; showCR:divs sum.
].
count >= nMaxPrint ifTrue: exit
]
]
].
 
Transcript showCR:'first 25 odd abundant numbers:'.
"from set of abdundant numbers >= 3, print 1st to 25th"
printNAbundant value:3 value:1 value:25.
 
Transcript cr; showCR:'first odd abundant number above 1000000000:'.
"from set of abdundant numbers >= 1000000000, print 1st to 1st"
printNAbundant value:1000000000 value:1 value:1.
 
Transcript cr; showCR:'first odd abundant number above 1000000000000:'.
"from set of abdundant numbers >= 1000000000, print 1st to 1st"
printNAbundant value:1000000000000 value:1 value:1.
 
Transcript cr; showCR:'the 1000th odd abundant number is:'.
"from set of abdundant numbers>= 3, print 1000th to 1000th"
printNAbundant value:3 value:1000 value:1000.</syntaxhighlight>
{{out}}
<pre>first 25 odd abundant numbers:
945 -> #(1 3 5 7 9 15 21 27 35 45 63 105 135 189 315) sum = 975
1575 -> #(1 3 5 7 9 15 21 25 35 45 63 75 105 175 225 315 525) sum = 1649
2205 -> #(1 3 5 7 9 15 21 35 45 49 63 105 147 245 315 441 735) sum = 2241
2835 -> #(1 3 5 7 9 15 21 27 35 45 63 81 105 135 189 315 405 567 945) sum = 2973
3465 -> #(1 3 5 7 9 11 15 21 33 35 45 55 63 77 99 105 165 231 315 385 495 693 1155) sum = 4023
4095 -> #(1 3 5 7 9 13 15 21 35 39 45 63 65 91 105 117 195 273 315 455 585 819 1365) sum = 4641
4725 -> #(1 3 5 7 9 15 21 25 27 35 45 63 75 105 135 175 189 225 315 525 675 945 1575) sum = 5195
5355 -> #(1 3 5 7 9 15 17 21 35 45 51 63 85 105 119 153 255 315 357 595 765 1071 1785) sum = 5877
5775 -> #(1 3 5 7 11 15 21 25 33 35 55 75 77 105 165 175 231 275 385 525 825 1155 1925) sum = 6129
5985 -> #(1 3 5 7 9 15 19 21 35 45 57 63 95 105 133 171 285 315 399 665 855 1197 1995) sum = 6495
6435 -> #(1 3 5 9 11 13 15 33 39 45 55 65 99 117 143 165 195 429 495 585 715 1287 2145) sum = 6669
6615 -> #(1 3 5 7 9 15 21 27 35 45 49 63 105 135 147 189 245 315 441 735 945 1323 2205) sum = 7065
6825 -> #(1 3 5 7 13 15 21 25 35 39 65 75 91 105 175 195 273 325 455 525 975 1365 2275) sum = 7063
7245 -> #(1 3 5 7 9 15 21 23 35 45 63 69 105 115 161 207 315 345 483 805 1035 1449 2415) sum = 7731
7425 -> #(1 3 5 9 11 15 25 27 33 45 55 75 99 135 165 225 275 297 495 675 825 1485 2475) sum = 7455
7875 -> #(1 3 5 7 9 15 21 25 35 45 63 75 105 125 175 225 315 375 525 875 1125 1575 2625) sum = 8349
8085 -> #(1 3 5 7 11 15 21 33 35 49 55 77 105 147 165 231 245 385 539 735 1155 1617 2695) sum = 8331
8415 -> #(1 3 5 9 11 15 17 33 45 51 55 85 99 153 165 187 255 495 561 765 935 1683 2805) sum = 8433
8505 -> #(1 3 5 7 9 15 21 27 35 45 63 81 105 135 189 243 315 405 567 945 1215 1701 2835) sum = 8967
8925 -> #(1 3 5 7 15 17 21 25 35 51 75 85 105 119 175 255 357 425 525 595 1275 1785 2975) sum = 8931
9135 -> #(1 3 5 7 9 15 21 29 35 45 63 87 105 145 203 261 315 435 609 1015 1305 1827 3045) sum = 9585
9555 -> #(1 3 5 7 13 15 21 35 39 49 65 91 105 147 195 245 273 455 637 735 1365 1911 3185) sum = 9597
9765 -> #(1 3 5 7 9 15 21 31 35 45 63 93 105 155 217 279 315 465 651 1085 1395 1953 3255) sum = 10203
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) sum = 12645
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) sum = 11946
 
first odd abundant number above 1000000000:
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) sum = 1083561009
 
first odd abundant number above 1000000000000:
1000000000125 -> #(1 3 5 7 9 15 21 23 25 29 35 45 61 63 69 75 87 105 115 125 145 161 175 183 203 207 225 261 305 315 345 375 427 435 483 525 549 575 609 667 725 805 875 915 1015 1035 1125 1281 1305 1403 1449 1525 1575 1725 1769 1827 2001 2135 2175 2415 2625 2745 2875 3045 3121 3335 3625 3843 4025 4209 4575 4669 5075 5175 5307 6003 6405 6525 7015 7245 7625 7875 8625 8845 9135 9363 9821 10005 10675 10875 12075 12383 12627 13725 14007 15225 15605 15921 16675 19215 20125 21045 21847 22875 23345 25375 25875 26535 28089 29463 30015 32025 32625 35075 36225 37149 40687 42021 44225 45675 46815 49105 50025 53375 60375 61915 63135 65541 68625 70035 71783 76125 78025 79605 83375 88389 90509 96075 105225 109235 111447 116725 122061 132675 140445 147315 150075 160125 175375 181125 185745 190381 196623 203435 210105 215349 221125 228375 234075 245525 250125 271527 284809 309575 315675 327705 350175 358915 366183 390125 398025 441945 452545 480375 502481 526125 546175 557235 571143 583625 610305 633563 646047 663375 702225 736575 750375 814581 854427 928725 951905 983115 1017175 1050525 1076745 1170375 1227625 1332667 1357635 1424045 1507443 1547875 1578375 1638525 1713429 1750875 1794575 1830915 1900689 1990125 2081707 2209725 2262725 2512405 2563281 2730875 2786175 2855715 3051525 3167815 3230235 3511125 3682875 3998001 4072905 4272135 4378763 4522329 4643625 4759525 4915575 5085875 5252625 5383725 5521049 5702067 6245121 6663335 6788175 7120225 7537215 8192625 8567145 8972875 9154575 9503445 10408535 11048625 11313625 11994003 12562025 12816405 13136289 13930875 14278575 14571949 15257625 15839075 16151175 16563147 18735363 19990005 20364525 21360675 21893815 22611645 23797625 24577875 26918625 27605245 28510335 30651341 31225605 33316675 33940875 35601125 37686075 38647343 39408867 42835725 43715847 45772875 47517225 49689441 52042675 59970015 62810125 64082025 65681445 71392875 72859745 79195375 80755875 82815735 91954023 93676815 99950025 101822625 106803375 109469075 113058225 115942029 126984127 131147541 138026225 142551675 153256705 156128025 166583375 188430375 193236715 197044335 214178625 218579235 237586125 248447205 260213375 275862069 299850075 320410125 328407225 347826087 364298725 380952381 414078675 459770115 468384075 499750125 547345375 565291125 579710145 634920635 655737705 690131125 712758375 766283525 780640125 888888889 966183575 985221675 1092896175 1142857143 1242236025 1379310345 1499250375 1642036125 1739130435 1821493625 1904761905 2070393375 2298850575 2341920375 2666666667 2898550725 3174603175 3278688525 3831417625 4444444445 4830917875 4926108375 5464480875 5714285715 6211180125 6896551725 8000000001 8695652175 9523809525 11494252875 13333333335 14492753625 15873015875 16393442625 22222222225 28571428575 34482758625 40000000005 43478260875 47619047625 66666666675 111111111125 142857142875 200000000025 333333333375) sum = 1261075281795
 
the 1000th odd abundant 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) sum = 519361</pre>
 
=={{header|Swift}}==
 
<syntaxhighlight lang="swift">extension BinaryInteger {
@inlinable
public func factors(sorted: Bool = true) -> [Self] {
let maxN = Self(Double(self).squareRoot())
var res = Set<Self>()
 
for factor in stride(from: 1, through: maxN, by: 1) where self % factor == 0 {
res.insert(factor)
res.insert(self / factor)
}
 
return sorted ? res.sorted() : Array(res)
}
}
 
@inlinable
public func isAbundant<T: BinaryInteger>(n: T) -> (Bool, [T]) {
let divs = n.factors().dropLast()
 
return (divs.reduce(0, +) > n, Array(divs))
}
 
let oddAbundant = (0...).lazy.filter({ $0 & 1 == 1 }).map({ ($0, isAbundant(n: $0)) }).filter({ $1.0 })
 
for (n, (_, factors)) in oddAbundant.prefix(25) {
print("n: \(n); sigma: \(factors.reduce(0, +))")
}
 
let (bigA, (_, bigFactors)) =
(1_000_000_000...)
.lazy
.filter({ $0 & 1 == 1 })
.map({ ($0, isAbundant(n: $0)) })
.first(where: { $1.0 })!
 
print("first odd abundant number over 1 billion: \(bigA), sigma: \(bigFactors.reduce(0, +))")</syntaxhighlight>
 
{{out}}
 
<pre style="overflow: scroll; height: 20em">n: 945; sigma: 975
n: 1575; sigma: 1649
n: 2205; sigma: 2241
n: 2835; sigma: 2973
n: 3465; sigma: 4023
n: 4095; sigma: 4641
n: 4725; sigma: 5195
n: 5355; sigma: 5877
n: 5775; sigma: 6129
n: 5985; sigma: 6495
n: 6435; sigma: 6669
n: 6615; sigma: 7065
n: 6825; sigma: 7063
n: 7245; sigma: 7731
n: 7425; sigma: 7455
n: 7875; sigma: 8349
n: 8085; sigma: 8331
n: 8415; sigma: 8433
n: 8505; sigma: 8967
n: 8925; sigma: 8931
n: 9135; sigma: 9585
n: 9555; sigma: 9597
n: 9765; sigma: 10203
n: 10395; sigma: 12645
n: 11025; sigma: 11946
first odd abundant number over 1 billion: 1000000575, sigma: 1083561009</pre>
 
=={{header|uBasic/4tH}}==
{{trans|C}}
<syntaxhighlight lang="text">c = 0
For n = 1 Step 2 While c < 25
If n < FUNC(_SumProperDivisors(n)) Then
c = c + 1
Print Using "_#"; c; Using " ____#"; n
EndIf
Next
For n = n Step 2 While c < 1000
If n < FUNC(_SumProperDivisors(n)) Then c = c + 1
Next
Print "\nThe one thousandth abundant odd number is: "; n
For n = 1000000001 Step 2
Until n < FUNC(_SumProperDivisors(n))
Next
Print "The first abundant odd number above one billion is: "; n
End
 
' The following function is for odd numbers ONLY
 
_SumProperDivisors
Param (1)
Local (3)
b@ = 1
For c@ = 3 To FUNC(_Sqrt(a@)) Step 2
If (a@ % c@) = 0 Then b@ = b@ + c@ + Iif (c@ = Set(d@, a@/c@), 0, d@)
Next
Return (b@)
 
_Sqrt
Param (1)
Local (3)
 
Let b@ = 1
Let c@ = 0
 
Do Until b@ > a@
Let b@ = b@ * 4
Loop
 
Do While b@ > 1
Let b@ = b@ / 4
Let d@ = a@ - c@ - b@
Let c@ = c@ / 2
If d@ > -1 Then
Let a@ = d@
Let c@ = c@ + b@
Endif
Loop
 
Return (c@)</syntaxhighlight>
{{out}}
<pre> 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
 
0 OK, 0:479
</pre>
 
=={{header|Visual Basic .NET}}==
{{Trans|ALGOL 68}}
<langsyntaxhighlight lang="vbnet">Module AbundantOddNumbers
' find some abundant odd numbers - numbers where the sum of the proper
' divisors is bigger than the number
Line 3,399 ⟶ 6,665:
Loop
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre>
Line 3,432 ⟶ 6,698:
First abundant odd number > 1 000 000 000:
1000000575 proper divisor sum: 1083561009
</pre>
 
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn divisors(n i64) []i64 {
mut divs := [i64(1)]
mut divs2 := []i64{}
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs << i
if i != j {
divs2 << j
}
}
}
for i := divs2.len - 1; i >= 0; i-- {
divs << divs2[i]
}
return divs
}
fn sum(divs []i64) i64 {
mut tot := i64(0)
for div in divs {
tot += div
}
return tot
}
fn sum_str(divs []i64) string {
mut s := ""
for div in divs {
s += "${u8(div)} + "
}
return s[0..s.len-3]
}
fn abundant_odd(search_from i64, count_from int, count_to int, print_one bool) i64 {
mut count := count_from
mut n := search_from
for ; count < count_to; n += 2 {
divs := divisors(n)
tot := sum(divs)
if tot > n {
count++
if print_one && count < count_to {
continue
}
s := sum_str(divs)
if !print_one {
println("${count:2}. ${n:5} < $s = $tot")
} else {
println("$n < $s = $tot")
}
}
}
return n
}
 
const max = 25
 
fn main() {
println("The first $max abundant odd numbers are:")
n := abundant_odd(1, 0, 25, false)
println("\nThe one thousandth abundant odd number is:")
abundant_odd(n, 25, 1000, true)
println("\nThe first abundant odd number above one billion is:")
abundant_odd(1_000_000_001, 0, 1, true)
}</syntaxhighlight>
 
{{out}}
<pre>
Same as Go entry
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="wren">import "./fmt" for Fmt
import "./math" for Int, Nums
var sumStr = Fn.new { |divs| divs.reduce("") { |acc, div| acc + "%(div) + " }[0...-3] }
var abundantOdd = Fn.new { |searchFrom, countFrom, countTo, printOne|
var count = countFrom
var n = searchFrom
while (count < countTo) {
var divs = Int.properDivisors(n)
var tot = Nums.sum(divs)
if (tot > n) {
count = count + 1
if (!printOne || count >= countTo) {
var s = sumStr.call(divs)
if (!printOne) {
Fmt.print("$2d. $5d < $s = $d", count, n, s, tot)
} else {
Fmt.print("$d < $s = $d", n, s, tot)
}
}
}
n = n + 2
}
return n
}
var MAX = 25
System.print("The first %(MAX) abundant odd numbers are:")
var n = abundantOdd.call(1, 0, 25, false)
System.print("\nThe one thousandth abundant odd number is:")
abundantOdd.call(n, 25, 1000, true)
System.print("\nThe first abundant odd number above one billion is:")
abundantOdd.call(1e9+1, 0, 1, true)</syntaxhighlight>
 
{{out}}
<pre>
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
</pre>
 
=={{header|X86 Assembly}}==
Assemble with tasm and tlink /t
<syntaxhighlight lang="asm"> .model tiny
.code
.486
org 100h
;ebp=counter, edi=Num, ebx=Div, esi=Sum
start: xor ebp, ebp ;odd abundant number counter:= 0
mov edi, 3 ;Num:= 3
ab10: mov ebx, 3 ;Div:= 3
mov esi, 1 ;Sum:= 1
ab20: mov eax, edi ;Quot:= Num/Div
cdq ;edx:= 0
div ebx ;eax(q):edx(r):= edx:eax/ebx
cmp ebx, eax ;if Div > Quot then quit loop
jge ab50
test edx, edx ;if remainder = 0 then
jne ab30
add esi, ebx ; Sum:= Sum + Div
cmp ebx, eax ; if Div # Quot then
je ab30
add esi, eax ; Sum:= Sum + Quot
ab30: add ebx, 2 ;Div:= Div+2 (only check odd Nums)
jmp ab20 ;loop
ab50:
cmp esi, edi ;if Sum > Num then
jle ab80
inc ebp ; counter:= counter+1
cmp ebp, 25 ; if counter<=25 or counter>=1000 then
jle ab60
cmp ebp, 1000
jl ab80
ab60: mov eax, edi ; print Num
call numout
mov al, ' ' ; print spaces
int 29h
int 29h
mov eax, esi ; print Sum
call numout
mov al, 0Dh ; carriage return
int 29h
mov al, 0Ah ; line feed
int 29h
cmp ebp, 1000 ; if counter = 1000 then
jne ab65
mov edi, 1000000001-2 ; Num:= 1,000,000,001 - 2
ab65: cmp edi, 1000000000 ; if Num > 1,000,000,000 then exit
jg ab90
ab80: add edi, 2 ;Num:= Num+2 (only check odd Nums)
jmp ab10 ;loop
ab90: ret
 
;Print signed integer in eax with commas, e.g: 12,345,010
numout: xor ecx, ecx ;digit counter:= 0
no00: cdq ;edx:= 0
mov ebx, 10 ;Num:= Num/10
div ebx ;eax(q):edx(r):= edx:eax/ebx
push edx ;remainder = least significant digit
inc ecx ;count digit
test eax, eax ;if Num # 0 then NumOut(Num)
je no20
call no00
no20: pop eax ;print digit + '0'
add al, '0'
int 29h
dec ecx ;un-count digit
je no30 ;if counter # 0 and
mov al, cl ; if remainder(counter/3) = 0 then
aam 3
jne no30
mov al, ',' ; print ','
int 29h
no30: ret
end start</syntaxhighlight>
{{out}}
<pre>
945 975
1,575 1,649
2,205 2,241
2,835 2,973
3,465 4,023
4,095 4,641
4,725 5,195
5,355 5,877
5,775 6,129
5,985 6,495
6,435 6,669
6,615 7,065
6,825 7,063
7,245 7,731
7,425 7,455
7,875 8,349
8,085 8,331
8,415 8,433
8,505 8,967
8,925 8,931
9,135 9,585
9,555 9,597
9,765 10,203
10,395 12,645
11,025 11,946
492,975 519,361
1,000,000,575 1,083,561,009
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">int Cnt, Num, Div, Sum, Quot;
[Cnt:= 0;
Num:= 3; \find odd abundant numbers
loop [Div:= 1;
Sum:= 0;
loop [Quot:= Num/Div;
if Div > Quot then quit;
if rem(0) = 0 then
[Sum:= Sum + Div;
if Div # Quot then Sum:= Sum + Quot;
];
Div:= Div+2;
];
if Sum > 2*Num then
[Cnt:= Cnt+1;
if Cnt<=25 or Cnt>=1000 then
[IntOut(0, Num); ChOut(0, 9);
IntOut(0, Sum); CrLf(0);
if Cnt = 1000 then Num:= 1_000_000_001 - 2;
if Num > 1_000_000_000 then quit;
];
];
Num:= Num+2;
];
]</syntaxhighlight>
 
{{out}}
<pre>
945 1920
1575 3224
2205 4446
2835 5808
3465 7488
4095 8736
4725 9920
5355 11232
5775 11904
5985 12480
6435 13104
6615 13680
6825 13888
7245 14976
7425 14880
7875 16224
8085 16416
8415 16848
8505 17472
8925 17856
9135 18720
9555 19152
9765 19968
10395 23040
11025 22971
492975 1012336
1000000575 2083561584
</pre>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn oddAbundants(startAt=3){ //--> iterator
Walker.zero().tweak(fcn(rn){
n:=rn.value;
Line 3,448 ⟶ 7,030:
}
}.fp(Ref(startAt.isOdd and startAt or startAt+1)))
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">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);
Line 3,460 ⟶ 7,042:
println("%6,d: %6,d = %s".fmt(n, ds.sum(0), ds.sort().concat(" + ")))
}
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">oaw:=oddAbundants();
 
println("First 25 abundant odd numbers:");
Line 3,470 ⟶ 7,052:
 
println("\nThe first abundant odd number above one billion is:");
printOAs(oddAbundants(1_000_000_000).next());</langsyntaxhighlight>
{{out}}
<pre style="height:45ex; font-size:83%">
2,289

edits