Abundant odd numbers: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 29: Line 29:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V oddNumber = 1
<syntaxhighlight lang=11l>V oddNumber = 1
V aCount = 0
V aCount = 0
V dSum = 0
V dSum = 0
Line 69: Line 69:
print("\nFirst abundant odd number > 1 000 000 000:")
print("\nFirst abundant odd number > 1 000 000 000:")
print(‘ ’oddNumber‘ proper divisor sum: ’dSum)
print(‘ ’oddNumber‘ proper divisor sum: ’dSum)
oddNumber += 2</lang>
oddNumber += 2</syntaxhighlight>


{{out}}
{{out}}
Line 108: Line 108:


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
<lang 360asm>* Abundant odd numbers 18/09/2019
<syntaxhighlight lang=360asm>* Abundant odd numbers 18/09/2019
ABUNODDS CSECT
ABUNODDS CSECT
USING ABUNODDS,R13 base register
USING ABUNODDS,R13 base register
Line 192: Line 192:
XDEC DS CL12 temp for edit
XDEC DS CL12 temp for edit
REGEQU equate registers
REGEQU equate registers
END ABUNODDS</lang>
END ABUNODDS</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 226: Line 226:
=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<lang AArch64 Assembly>
<syntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program abundant64.s */
/* program abundant64.s */
Line 774: Line 774:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{output}}
{{output}}
<pre>
<pre>
Line 815: Line 815:
[[http://rosettacode.org/wiki/Proper_divisors#Ada]].
[[http://rosettacode.org/wiki/Proper_divisors#Ada]].


<lang Ada>with Ada.Text_IO, Generic_Divisors;
<syntaxhighlight lang=Ada>with Ada.Text_IO, Generic_Divisors;


procedure Odd_Abundant is
procedure Odd_Abundant is
Line 871: Line 871:
end loop;
end loop;
Print_Abundant_Line(1, Current, False);
Print_Abundant_Line(1, Current, False);
end Odd_Abundant;</lang>
end Odd_Abundant;</syntaxhighlight>


{{out}}
{{out}}
Line 907: Line 907:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>BEGIN
<syntaxhighlight lang=algol68>BEGIN
# find some abundant odd numbers - numbers where the sum of the proper #
# find some abundant odd numbers - numbers where the sum of the proper #
# divisors is bigger than the number #
# divisors is bigger than the number #
Line 982: Line 982:
OD
OD
END
END
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,020: Line 1,020:
{{Trans|ALGOL 68}}
{{Trans|ALGOL 68}}
Using the divisor_sum procedure from the [[Sum_of_divisors#ALGOL_W]] task.
Using the divisor_sum procedure from the [[Sum_of_divisors#ALGOL_W]] task.
<lang algolw>begin
<syntaxhighlight lang=algolw>begin
% find some abundant odd numbers - numbers where the sum of the proper %
% find some abundant odd numbers - numbers where the sum of the proper %
% divisors is bigger than the number %
% divisors is bigger than the number %
Line 1,094: Line 1,094:
end while_not_foundOddAn ;
end while_not_foundOddAn ;
end
end
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,131: Line 1,131:
=={{header|AppleScript}}==
=={{header|AppleScript}}==


<lang applescript>on aliquotSum(n)
<syntaxhighlight lang=applescript>on aliquotSum(n)
if (n < 2) then return 0
if (n < 2) then return 0
set sum to 1
set sum to 1
Line 1,183: Line 1,183:
set output to output as text
set output to output as text
set AppleScript's text item delimiters to astid
set AppleScript's text item delimiters to astid
return output</lang>
return output</syntaxhighlight>


{{output}}
{{output}}


<lang applescript>"The first 25 abundant odd numbers:
<syntaxhighlight lang=applescript>"The first 25 abundant odd numbers:
945 (proper divisor sum: 975)
945 (proper divisor sum: 975)
1575 (proper divisor sum: 1649)
1575 (proper divisor sum: 1649)
Line 1,216: Line 1,216:
492975 (proper divisor sum: 519361)
492975 (proper divisor sum: 519361)
The first > 1,000,000,000:
The first > 1,000,000,000:
1000000575 (proper divisor sum: 1083561009)"</lang>
1000000575 (proper divisor sum: 1083561009)"</syntaxhighlight>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<lang ARM Assembly>
<syntaxhighlight lang=ARM Assembly>
/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
/* program abundant.s */
/* program abundant.s */
Line 1,737: Line 1,737:
/***************************************************/
/***************************************************/
.include "../affichage.inc"
.include "../affichage.inc"
</syntaxhighlight>
</lang>
<pre>
<pre>
Program start
Program start
Line 1,775: Line 1,775:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>abundant?: function [n]-> (2*n) < sum factors n
<syntaxhighlight lang=rebol>abundant?: function [n]-> (2*n) < sum factors n


print "the first 25 abundant odd numbers:"
print "the first 25 abundant odd numbers:"
Line 1,803: Line 1,803:
]
]
'i + 2
'i + 2
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 1,837: Line 1,837:


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>Abundant(num){
<syntaxhighlight lang=AutoHotkey>Abundant(num){
sum := 0, str := ""
sum := 0, str := ""
for n, bool in proper_divisors(num)
for n, bool in proper_divisors(num)
Line 1,856: Line 1,856:
Array[i] := true
Array[i] := true
return Array
return Array
}</lang>
}</syntaxhighlight>
Examples:<lang AutoHotkey>output := "First 25 abundant odd numbers:`n"
Examples:<syntaxhighlight lang=AutoHotkey>output := "First 25 abundant odd numbers:`n"
while (count<1000)
while (count<1000)
{
{
Line 1,881: Line 1,881:
}
}
MsgBox % output
MsgBox % output
return</lang>
return</syntaxhighlight>
{{out}}
{{out}}
<pre>First 25 abundant odd numbers:
<pre>First 25 abundant odd numbers:
Line 1,922: Line 1,922:


=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>
<syntaxhighlight lang=AWK>
# syntax: GAWK -f ABUNDANT_ODD_NUMBERS.AWK
# syntax: GAWK -f ABUNDANT_ODD_NUMBERS.AWK
# converted from C
# converted from C
Line 1,957: Line 1,957:
return(sum)
return(sum)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,992: Line 1,992:
=={{header|BASIC256}}==
=={{header|BASIC256}}==
{{trans|Visual Basic .NET}}
{{trans|Visual Basic .NET}}
<lang BASIC256>
<syntaxhighlight lang=BASIC256>
numimpar = 1
numimpar = 1
contar = 0
contar = 0
Line 2,046: Line 2,046:
End While
End While
End
End
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang=c>#include <stdio.h>
#include <math.h>
#include <math.h>


Line 2,071: Line 2,071:
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>1: 945
<pre>1: 945
Line 2,103: Line 2,103:


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using static System.Console;
<syntaxhighlight lang=csharp>using static System.Console;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
Line 2,129: Line 2,129:


static string Format(this (int n, int sum) pair) => $"{pair.n:N0} with sum {pair.sum:N0}";
static string Format(this (int n, int sum) pair) => $"{pair.n:N0} with sum {pair.sum:N0}";
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,165: Line 2,165:
=={{header|C++}}==
=={{header|C++}}==
{{trans|Go}}
{{trans|Go}}
<lang cpp>#include <algorithm>
<syntaxhighlight lang=cpp>#include <algorithm>
#include <iostream>
#include <iostream>
#include <numeric>
#include <numeric>
Line 2,246: Line 2,246:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 2,282: Line 2,282:


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>% Integer square root
<syntaxhighlight lang=clu>% Integer square root
isqrt = proc (s: int) returns (int)
isqrt = proc (s: int) returns (int)
x0: int := s / 2
x0: int := s / 2
Line 2,343: Line 2,343:
break
break
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>1: 945 aliquot: 975
<pre>1: 945 aliquot: 975
Line 2,381: Line 2,381:
Using the ''iterate'' library instead of the standard ''loop'' or ''do''.
Using the ''iterate'' library instead of the standard ''loop'' or ''do''.


<lang lisp>;; * Loading the external libraries
<syntaxhighlight lang=lisp>;; * Loading the external libraries
(eval-when (:compile-toplevel :load-toplevel)
(eval-when (:compile-toplevel :load-toplevel)
(ql:quickload '("cl-annot" "iterate" "alexandria")))
(ql:quickload '("cl-annot" "iterate" "alexandria")))
Line 2,446: Line 2,446:
@type fixnum n sum-of-divisors
@type fixnum n sum-of-divisors
(until (< n sum-of-divisors))
(until (< n sum-of-divisors))
(finally (format t "~D ~D~%~%" n sum-of-divisors)))))</lang>
(finally (format t "~D ~D~%~%" n sum-of-divisors)))))</syntaxhighlight>


{{out}}
{{out}}
Line 2,493: Line 2,493:
=={{header|D}}==
=={{header|D}}==
{{trans|C++}}
{{trans|C++}}
<lang d>import std.stdio;
<syntaxhighlight lang=d>import std.stdio;


int[] divisors(int n) {
int[] divisors(int n) {
Line 2,551: Line 2,551:
writeln("\nThe first abundant odd number above one billion is:");
writeln("\nThe first abundant odd number above one billion is:");
abundantOdd(cast(int)(1e9 + 1), 0, 1, true);
abundantOdd(cast(int)(1e9 + 1), 0, 1, true);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 2,588: Line 2,588:
=={{header|Delphi}}==
=={{header|Delphi}}==
{{trans|C}}
{{trans|C}}
<lang delphi>program AbundantOddNumbers;
<syntaxhighlight lang=delphi>program AbundantOddNumbers;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 2,635: Line 2,635:


end.
end.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>1: 945
<pre>1: 945
Line 2,667: Line 2,667:


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang=fsharp>
// Abundant odd numbers. Nigel Galloway: August 1st., 2021
// 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 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))
Line 2,674: Line 2,674:
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 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
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>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,709: Line 2,709:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: arrays formatting io kernel lists lists.lazy math
<syntaxhighlight lang=factor>USING: arrays formatting io kernel lists lists.lazy math
math.primes.factors sequences tools.memory.private ;
math.primes.factors sequences tools.memory.private ;
IN: rosetta-code.abundant-odd-numbers
IN: rosetta-code.abundant-odd-numbers
Line 2,733: Line 2,733:
[ print show nl ] 2tri@ ;
[ print show nl ] 2tri@ ;


MAIN: abundant-odd-numbers-demo</lang>
MAIN: abundant-odd-numbers-demo</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,773: Line 2,773:
A basic direct solution. A more robust alternative would be to find
A basic direct solution. A more robust alternative would be to find
the prime factors and then use a formulaic approach.
the prime factors and then use a formulaic approach.
<lang fortran>
<syntaxhighlight lang=fortran>
program main
program main
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
Line 2,821: Line 2,821:


end program main
end program main
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,857: Line 2,857:
=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
{{trans|Visual Basic .NET}}
{{trans|Visual Basic .NET}}
<lang freebasic>
<syntaxhighlight lang=freebasic>
Declare Function SumaDivisores(n As Integer) As Integer
Declare Function SumaDivisores(n As Integer) As Integer


Line 2,915: Line 2,915:
Loop
Loop
End
End
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,954: Line 2,954:
=={{header|Frink}}==
=={{header|Frink}}==
Frink has efficient functions for factoring numbers that use trial division, wheel factoring, and Pollard rho factoring.
Frink has efficient functions for factoring numbers that use trial division, wheel factoring, and Pollard rho factoring.
<lang frink>isAbundantOdd[n] := sum[allFactors[n, true, false]] > n
<syntaxhighlight lang=frink>isAbundantOdd[n] := sum[allFactors[n, true, false]] > n


n = 3
n = 3
Line 2,996: Line 2,996:
println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]]
println["$n: proper divisor sum " + sum[allFactors[n, 1, false]]]
</lang>
</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,035: Line 3,035:
=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
{{trans|C}}
{{trans|C}}
<lang futurebasic>
<syntaxhighlight lang=futurebasic>
include "NSLog.incl"
include "NSLog.incl"


Line 3,054: Line 3,054:


HandleEvents
HandleEvents
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,089: Line 3,089:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 3,161: Line 3,161:
fmt.Println("\nThe first abundant odd number above one billion is:")
fmt.Println("\nThe first abundant odd number above one billion is:")
abundantOdd(1e9+1, 0, 1, true)
abundantOdd(1e9+1, 0, 1, true)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,201: Line 3,201:
=={{header|Groovy}}==
=={{header|Groovy}}==
{{trans|Java}}
{{trans|Java}}
<lang groovy>class Abundant {
<syntaxhighlight lang=groovy>class Abundant {
static List<Integer> divisors(int n) {
static List<Integer> divisors(int n) {
List<Integer> divs = new ArrayList<>()
List<Integer> divs = new ArrayList<>()
Line 3,265: Line 3,265:
abundantOdd((int) (1e9 + 1), 0, 1, true)
abundantOdd((int) (1e9 + 1), 0, 1, true)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 3,301: Line 3,301:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang Haskell>import Data.List (nub)
<syntaxhighlight lang=Haskell>import Data.List (nub)


divisorSum :: Integral a => a -> a
divisorSum :: Integral a => a -> a
Line 3,329: Line 3,329:
printAbundant $ oddAbundants 1 !! 1000
printAbundant $ oddAbundants 1 !! 1000
putStrLn "The first odd abundant number above 1000000000 is:"
putStrLn "The first odd abundant number above 1000000000 is:"
printAbundant . head . oddAbundants $ 10 ^ 9</lang>
printAbundant . head . oddAbundants $ 10 ^ 9</syntaxhighlight>


{{out}}
{{out}}
Line 3,364: Line 3,364:


Or, importing Data.Numbers.Primes (and significantly faster):
Or, importing Data.Numbers.Primes (and significantly faster):
<lang haskell>import Data.List (group, sort)
<syntaxhighlight lang=haskell>import Data.List (group, sort)
import Data.Numbers.Primes
import Data.Numbers.Primes


Line 3,402: Line 3,402:
( [1 + billion, 3 + billion ..]
( [1 + billion, 3 + billion ..]
>>= abundantTuple
>>= abundantTuple
)</lang>
)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
<pre>First 25 abundant odd numbers with their divisor sums:
Line 3,479: Line 3,479:


=={{header|Java}}==
=={{header|Java}}==
<lang java>import java.util.ArrayList;
<syntaxhighlight lang=java>import java.util.ArrayList;
import java.util.List;
import java.util.List;


Line 3,524: Line 3,524:
}
}


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,566: Line 3,566:
Composing reusable functions and generators:
Composing reusable functions and generators:
{{Trans|Python}}
{{Trans|Python}}
<lang javascript>(() => {
<syntaxhighlight lang=javascript>(() => {
'use strict';
'use strict';
const main = () => {
const main = () => {
Line 3,776: Line 3,776:
// MAIN ---
// MAIN ---
return main();
return main();
})();</lang>
})();</syntaxhighlight>
{{Out}}
{{Out}}
<pre>First 25 abundant odd numbers, with their divisor sums:
<pre>First 25 abundant odd numbers, with their divisor sums:
Line 3,812: Line 3,812:


=={{header|jq}}==
=={{header|jq}}==
<syntaxhighlight lang=jq>
<lang jq>
# The factors, unsorted
# The factors, unsorted
def factors:
def factors:
Line 3,828: Line 3,828:
| (factors | add) as $sum
| (factors | add) as $sum
| select($sum > 2*.)
| select($sum > 2*.)
| [., $sum] ;</lang>
| [., $sum] ;</syntaxhighlight>


Computing the first abundant number greater than 10^9 is presently impractical using jq, but for the other tasks:
Computing the first abundant number greater than 10^9 is presently impractical using jq, but for the other tasks:
Line 3,837: Line 3,837:
+ nth(999; abundant_odd_numbers))
+ nth(999; abundant_odd_numbers))
| @tsv
| @tsv
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 3,871: Line 3,871:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang=julia>using Primes


function propfact(n)
function propfact(n)
Line 3,909: Line 3,909:
println("The first abundant odd number greater than one billion:")
println("The first abundant odd number greater than one billion:")
oddabundantsfrom(1000000000, 1)
oddabundantsfrom(1000000000, 1)
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
First 25 abundant odd numbers:
First 25 abundant odd numbers:
Line 3,944: Line 3,944:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|D}}
{{trans|D}}
<lang scala>fun divisors(n: Int): List<Int> {
<syntaxhighlight lang=scala>fun divisors(n: Int): List<Int> {
val divs = mutableListOf(1)
val divs = mutableListOf(1)
val divs2 = mutableListOf<Int>()
val divs2 = mutableListOf<Int>()
Line 4,001: Line 4,001:
println("\nThe first abundant odd number above one billion is:")
println("\nThe first abundant odd number above one billion is:")
abundantOdd((1e9 + 1).toInt(), 0, 1, true)
abundantOdd((1e9 + 1).toInt(), 0, 1, true)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 4,038: Line 4,038:
=={{header|Lobster}}==
=={{header|Lobster}}==
{{trans|C}}
{{trans|C}}
<lang Lobster>
<syntaxhighlight lang=Lobster>
// Note that the following function is for odd numbers only
// Note that the following function is for odd numbers only
// Use "for (unsigned i = 2; i*i <= n; i++)" for even and odd numbers
// Use "for (unsigned i = 2; i*i <= n; i++)" for even and odd numbers
Line 4,080: Line 4,080:


abundant_odd_numbers()
abundant_odd_numbers()
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 4,114: Line 4,114:


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>-- Return the sum of the proper divisors of x
<syntaxhighlight lang=lua>-- Return the sum of the proper divisors of x
function sumDivs (x)
function sumDivs (x)
local sum, sqr = 1, math.sqrt(x)
local sum, sqr = 1, math.sqrt(x)
Line 4,150: Line 4,150:
for k, v in pairs(oddAbundants("First", 25)) do showResult(k, v) end
for k, v in pairs(oddAbundants("First", 25)) do showResult(k, v) end
showResult("1000", oddAbundants("Nth", 1000))
showResult("1000", oddAbundants("Nth", 1000))
showResult("Above 1e6", oddAbundants("Above", 1e6))</lang>
showResult("Above 1e6", oddAbundants("Above", 1e6))</syntaxhighlight>
{{out}}
{{out}}
<pre>1: the proper divisors of 945 sum to 975
<pre>1: the proper divisors of 945 sum to 975
Line 4,182: Line 4,182:
=={{header|MAD}}==
=={{header|MAD}}==


<lang MAD> NORMAL MODE IS INTEGER
<syntaxhighlight lang=MAD> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(ND)
INTERNAL FUNCTION(ND)
Line 4,216: Line 4,216:
VECTOR VALUES HUGENO =
VECTOR VALUES HUGENO =
0 $25HFIRST ABOVE 1 BILLION IS ,I10,S1,7HDIVSUM ,I10*$
0 $25HFIRST ABOVE 1 BILLION IS ,I10,S1,7HDIVSUM ,I10*$
END OF PROGRAM</lang>
END OF PROGRAM</syntaxhighlight>


{{out}}
{{out}}
Line 4,252: Line 4,252:
=={{header|Maple}}==
=={{header|Maple}}==


<lang Maple>
<syntaxhighlight lang=Maple>
with(NumberTheory):
with(NumberTheory):


Line 4,293: Line 4,293:
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));
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>
</lang>
{{out}}<pre>
{{out}}<pre>
"First 25 abundant odd numbers"
"First 25 abundant odd numbers"
Line 4,354: Line 4,354:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==


<lang Mathematica>ClearAll[AbundantQ]
<syntaxhighlight lang=Mathematica>ClearAll[AbundantQ]
AbundantQ[n_] := TrueQ[Greater[Total @ Most @ Divisors @ n, n]]
AbundantQ[n_] := TrueQ[Greater[Total @ Most @ Divisors @ n, n]]
res = {};
res = {};
Line 4,384: Line 4,384:
i += 2;
i += 2;
];
];
res</lang>
res</syntaxhighlight>
{{out}}
{{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}}
<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}}
Line 4,391: Line 4,391:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>block([k: 0, n: 1, l: []],
<syntaxhighlight lang=maxima>block([k: 0, n: 1, l: []],
while k < 25 do (
while k < 25 do (
n: n+2,
n: n+2,
Line 4,400: Line 4,400:
),
),
return(l)
return(l)
);</lang>
);</syntaxhighlight>
{{out}}
{{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>
<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>


<lang maxima>block([k: 0, n: 1],
<syntaxhighlight lang=maxima>block([k: 0, n: 1],
while k < 1000 do (
while k < 1000 do (
n: n+2,
n: n+2,
Line 4,410: Line 4,410:
),
),
return([n,divsum(n)])
return([n,divsum(n)])
);</lang>
);</syntaxhighlight>
{{out}}
{{out}}
<pre>[492975,1012336]</pre>
<pre>[492975,1012336]</pre>


<lang maxima>block([n: 5, l: [5], r: divsum(n,-1)],
<syntaxhighlight lang=maxima>block([n: 5, l: [5], r: divsum(n,-1)],
while n < 10^8 do (
while n < 10^8 do (
if not mod(n,3)=0 then (
if not mod(n,3)=0 then (
Line 4,423: Line 4,423:
),
),
return(l)
return(l)
);</lang>
);</syntaxhighlight>
{{out}}
{{out}}
<pre>[5,25,35,175,385,1925,5005,25025,85085,425425,1616615,8083075,37182145,56581525]</pre>
<pre>[5,25,35,175,385,1925,5005,25025,85085,425425,1616615,8083075,37182145,56581525]</pre>


=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>
<syntaxhighlight lang=Nim>
from math import sqrt
from math import sqrt
import strformat
import strformat
Line 4,483: Line 4,483:
echo fmt"The sum of its proper divisors is {s}."
echo fmt"The sum of its proper divisors is {s}."
break
break
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 4,572: Line 4,572:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free Pascal}} {{works with|Delphi}}
{{works with|Free Pascal}} {{works with|Delphi}}
<lang pascal>
<syntaxhighlight lang=pascal>
program AbundantOddNumbers;
program AbundantOddNumbers;
{$IFDEF FPC}
{$IFDEF FPC}
Line 4,752: Line 4,752:
Inc(N, 2);
Inc(N, 2);
WriteLn('The first abundant odd number above one billion is: ',OutNum(N));
WriteLn('The first abundant odd number above one billion is: ',OutNum(N));
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,793: Line 4,793:
{{trans|Raku}}
{{trans|Raku}}
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang=perl>use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 4,816: Line 4,816:
say for odd_abundants(1, 25);
say for odd_abundants(1, 25);
say "\nOne thousandth abundant odd number:\n", (odd_abundants(1, 1000))[999];
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);</lang>
say "\nFirst abundant odd number above one billion:\n", odd_abundants(999_999_999, 1);</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:20ex">First 25 abundant odd numbers:
<pre style="height:20ex">First 25 abundant odd numbers:
Line 4,852: Line 4,852:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<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>
<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>
<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>
<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>
Line 4,874: Line 4,874:
<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>
<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>
<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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 4,910: Line 4,910:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de accud (Var Key)
<syntaxhighlight lang=PicoLisp>(de accud (Var Key)
(if (assoc Key (val Var))
(if (assoc Key (val Var))
(con @ (inc (cdr @)))
(con @ (inc (cdr @)))
Line 4,955: Line 4,955:
'****
'****
1000000575
1000000575
(factor-sum 1000000575) ) )</lang>
(factor-sum 1000000575) ) )</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 4,988: Line 4,988:


=={{header|Processing}}==
=={{header|Processing}}==
<lang processing>void setup() {
<syntaxhighlight lang=processing>void setup() {
println("First 25 abundant odd numbers: ");
println("First 25 abundant odd numbers: ");
int abundant = 0;
int abundant = 0;
Line 5,030: Line 5,030:
}
}
return sum;
return sum;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>First 25 abundant odd numbers:
<pre>First 25 abundant odd numbers:
Line 5,065: Line 5,065:
=={{header|PureBasic}}==
=={{header|PureBasic}}==
{{trans|C}}
{{trans|C}}
<lang PureBasic>NewList l_sum.i()
<syntaxhighlight lang=PureBasic>NewList l_sum.i()




Line 5,134: Line 5,134:
Input()
Input()
EndIf</lang>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre> 1: 945 -&gt; 975 = 1+3+5+7+9+15+21+27+35+45+63+105+135+189+315
<pre> 1: 945 -&gt; 975 = 1+3+5+7+9+15+21+27+35+45+63+105+135+189+315
Line 5,171: Line 5,171:
===Procedural===
===Procedural===
{{trans|Visual Basic .NET}}
{{trans|Visual Basic .NET}}
<lang Python>#!/usr/bin/python
<syntaxhighlight lang=Python>#!/usr/bin/python
# Abundant odd numbers - Python
# Abundant odd numbers - Python


Line 5,216: Line 5,216:
print ("\nFirst abundant odd number > 1 000 000 000:")
print ("\nFirst abundant odd number > 1 000 000 000:")
print (" ",oddNumber," proper divisor sum: ",dSum)
print (" ",oddNumber," proper divisor sum: ",dSum)
oddNumber += 2</lang>
oddNumber += 2</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 5,254: Line 5,254:


===Functional===
===Functional===
<lang python>'''Odd abundant numbers'''
<syntaxhighlight lang=python>'''Odd abundant numbers'''


from math import sqrt
from math import sqrt
Line 5,354: Line 5,354:


if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
<pre>First 25 abundant odd numbers with their divisor sums:
Line 5,390: Line 5,390:


=={{header|q}}==
=={{header|q}}==
<lang q>s:{c where 0=x mod c:1+til x div 2} / proper divisors
<syntaxhighlight lang=q>s:{c where 0=x mod c:1+til x div 2} / proper divisors
sd:sum s@ / sum of proper divisors
sd:sum s@ / sum of proper divisors
abundant:{x<sd x}
abundant:{x<sd x}
Filter:{y where x each y}</lang>
Filter:{y where x each y}</syntaxhighlight>
Solution largely follows that for [[#J]], except the crucial definition of <code>s</code>.
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.
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}}
{{out}}
<lang q>q)count A:Filter[abundant] 1+2*til 260000 / a batch of abundant odd numbers; 1000+ is enough
<syntaxhighlight lang=q>q)count A:Filter[abundant] 1+2*til 260000 / a batch of abundant odd numbers; 1000+ is enough
1054
1054


Line 5,408: Line 5,408:


q)1 sd\(not abundant@)(2+)/1000000000-1 / first abundant odd number above 1,000,000,000 and its divisors
q)1 sd\(not abundant@)(2+)/1000000000-1 / first abundant odd number above 1,000,000,000 and its divisors
1000000575 1083561009</lang>
1000000575 1083561009</syntaxhighlight>
References:
References:
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/ref/ Language Reference]
Line 5,417: Line 5,417:
<code>factors</code> is defined at [[Factors of an integer#Quackery]].
<code>factors</code> is defined at [[Factors of an integer#Quackery]].


<lang Quackery> [ 0 swap factors witheach + ] is sigmasum ( n --> n )
<syntaxhighlight lang=Quackery> [ 0 swap factors witheach + ] is sigmasum ( n --> n )


0 -1 [ 2 +
0 -1 [ 2 +
Line 5,439: Line 5,439:
[ 2 + dup sigmasum
[ 2 + dup sigmasum
over 2 * > until ]
over 2 * > until ]
dup echo sp sigmasum echo cr</lang>
dup echo sp sigmasum echo cr</syntaxhighlight>


{{out}}
{{out}}
Line 5,475: Line 5,475:


=={{header|R}}==
=={{header|R}}==
<lang R># Abundant Odd Numbers
<syntaxhighlight lang=R># Abundant Odd Numbers


find_div_sum <- function(x){
find_div_sum <- function(x){
Line 5,515: Line 5,515:
# Get the first after 1e9
# Get the first after 1e9
cat("First odd abundant after 1e9 is")
cat("First odd abundant after 1e9 is")
get_n_abun(index = 1e9 + 1, total = 1, print_all = F)</lang>
get_n_abun(index = 1e9 + 1, total = 1, print_all = F)</syntaxhighlight>


{{Out}}
{{Out}}
Line 5,553: Line 5,553:
=={{header|Racket}}==
=={{header|Racket}}==


<lang racket>#lang racket
<syntaxhighlight lang=racket>#lang racket


(require math/number-theory
(require math/number-theory
Line 5,566: Line 5,566:
(for/list ([i (in-range 25)] [x (make-generator 0)]) x) ; Task 1
(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/last ([i (in-range 1000)] [x (make-generator 0)]) x) ; Task 2
(for/first ([x (make-generator (add1 (inexact->exact 1e9)))]) x) ; Task 3</lang>
(for/first ([x (make-generator (add1 (inexact->exact 1e9)))]) x) ; Task 3</syntaxhighlight>


{{out}}
{{out}}
Line 5,603: Line 5,603:
{{works with|Rakudo|2019.03}}
{{works with|Rakudo|2019.03}}


<lang perl6>sub odd-abundant (\x) {
<syntaxhighlight lang=perl6>sub odd-abundant (\x) {
my @l = x.is-prime ?? 1 !! flat
my @l = x.is-prime ?? 1 !! flat
1, (3 .. x.sqrt.floor).map: -> \d {
1, (3 .. x.sqrt.floor).map: -> \d {
Line 5,629: Line 5,629:
put "\nOne thousandth abundant odd number:\n" ~ odd-abundants( :start-at(1) )[999] ~
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>
"\n\nFirst abundant odd number above one billion:\n" ~ odd-abundants( :start-at(1_000_000_000) ).head;</syntaxhighlight>
{{out}}
{{out}}
<pre>First 25 abundant odd numbers:
<pre>First 25 abundant odd numbers:
Line 5,668: Line 5,668:


The &nbsp; '''sigO''' &nbsp; function is a specialized version of the &nbsp; '''sigma''' &nbsp; function optimized just for &nbsp; ''odd'' &nbsp; numbers.
The &nbsp; '''sigO''' &nbsp; function is a specialized version of the &nbsp; '''sigma''' &nbsp; function optimized just for &nbsp; ''odd'' &nbsp; numbers.
<lang rexx>/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandth, first > 1 billion. */
<syntaxhighlight lang=rexx>/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandth, first > 1 billion. */
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if Nlow=='' | Nlow=="," then Nlow= 25 /*Not specified? Then use the default.*/
if Nlow=='' | Nlow=="," then Nlow= 25 /*Not specified? Then use the default.*/
Line 5,707: Line 5,707:
end /*k*/ /* ___*/
end /*k*/ /* ___*/
if k*k==x then return s + k /*Was X a square? If so, add √ x */
if k*k==x then return s + k /*Was X a square? If so, add √ x */
return s /*return (sigma) sum of the divisors. */</lang>
return s /*return (sigma) sum of the divisors. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>
Line 5,742: Line 5,742:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang=ring>
#Project: Anbundant odd numbers
#Project: Anbundant odd numbers


Line 5,809: Line 5,809:
see "" + index + ". " + string(n) + ": divisor sum: " +
see "" + index + ". " + string(n) + ": divisor sum: " +
see string(nArray[m]) + " = " + string(sum) + nl + nl
see string(nArray[m]) + " = " + string(sum) + nl + nl
</syntaxhighlight>
</lang>


<pre>
<pre>
Line 5,874: Line 5,874:
=={{header|Ruby}}==
=={{header|Ruby}}==
proper_divisors method taken from http://rosettacode.org/wiki/Proper_divisors#Ruby
proper_divisors method taken from http://rosettacode.org/wiki/Proper_divisors#Ruby
<lang ruby>require "prime"
<syntaxhighlight lang=ruby>require "prime"
class Integer
class Integer
Line 5,899: Line 5,899:
puts "\n%d with sum %#d" % generator_odd_abundants.take(1000).last
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
puts "\n%d with sum %#d" % generator_odd_abundants(1_000_000_000).next
</syntaxhighlight>
</lang>


=={{header|Rust}}==
=={{header|Rust}}==
{{trans|Go}}
{{trans|Go}}
<lang rust>fn divisors(n: u64) -> Vec<u64> {
<syntaxhighlight lang=rust>fn divisors(n: u64) -> Vec<u64> {
let mut divs = vec![1];
let mut divs = vec![1];
let mut divs2 = Vec::new();
let mut divs2 = Vec::new();
Line 5,956: Line 5,956:
println!("The first abundant odd number above one billion is:");
println!("The first abundant odd number above one billion is:");
abundant_odd(1e9 as u64 + 1, 0, 1, true);
abundant_odd(1e9 as u64 + 1, 0, 1, true);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 5,992: Line 5,992:
=={{header|Scala}}==
=={{header|Scala}}==
{{trans|D}}
{{trans|D}}
<lang scala>import scala.collection.mutable.ListBuffer
<syntaxhighlight lang=scala>import scala.collection.mutable.ListBuffer


object Abundant {
object Abundant {
Line 6,051: Line 6,051:
abundantOdd((1e9 + 1).intValue(), 0, 1, printOne = true)
abundantOdd((1e9 + 1).intValue(), 0, 1, printOne = true)
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>The first 25 abundant odd numbers are:
<pre>The first 25 abundant odd numbers are:
Line 6,087: Line 6,087:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func is_abundant(n) {
<syntaxhighlight lang=ruby>func is_abundant(n) {
n.sigma > 2*n
n.sigma > 2*n
}
}
Line 6,113: Line 6,113:
with(odd_abundants(1e9).first) {|n|
with(odd_abundants(1e9).first) {|n|
printf(sep + fstr, '***', n, n.sigma-n)
printf(sep + fstr, '***', n, n.sigma-n)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 6,150: Line 6,150:


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
<lang smalltalk>divisors :=
<syntaxhighlight lang=smalltalk>divisors :=
[:nr |
[:nr |
|divs|
|divs|
Line 6,196: Line 6,196:
Transcript cr; showCR:'the 1000th odd abundant number is:'.
Transcript cr; showCR:'the 1000th odd abundant number is:'.
"from set of abdundant numbers>= 3, print 1000th to 1000th"
"from set of abdundant numbers>= 3, print 1000th to 1000th"
printNAbundant value:3 value:1000 value:1000.</lang>
printNAbundant value:3 value:1000 value:1000.</syntaxhighlight>
{{out}}
{{out}}
<pre>first 25 odd abundant numbers:
<pre>first 25 odd abundant numbers:
Line 6,236: Line 6,236:
=={{header|Swift}}==
=={{header|Swift}}==


<lang swift>extension BinaryInteger {
<syntaxhighlight lang=swift>extension BinaryInteger {
@inlinable
@inlinable
public func factors(sorted: Bool = true) -> [Self] {
public func factors(sorted: Bool = true) -> [Self] {
Line 6,271: Line 6,271:
.first(where: { $1.0 })!
.first(where: { $1.0 })!


print("first odd abundant number over 1 billion: \(bigA), sigma: \(bigFactors.reduce(0, +))")</lang>
print("first odd abundant number over 1 billion: \(bigA), sigma: \(bigFactors.reduce(0, +))")</syntaxhighlight>


{{out}}
{{out}}
Line 6,359: Line 6,359:
Loop
Loop


Return (c@)</lang>
Return (c@)</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 945
<pre> 1 945
Line 6,395: Line 6,395:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{Trans|ALGOL 68}}
{{Trans|ALGOL 68}}
<lang vbnet>Module AbundantOddNumbers
<syntaxhighlight lang=vbnet>Module AbundantOddNumbers
' find some abundant odd numbers - numbers where the sum of the proper
' find some abundant odd numbers - numbers where the sum of the proper
' divisors is bigger than the number
' divisors is bigger than the number
Line 6,453: Line 6,453:
Loop
Loop
End Sub
End Sub
End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 6,490: Line 6,490:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|go}}
{{trans|go}}
<lang vlang>fn divisors(n i64) []i64 {
<syntaxhighlight lang=vlang>fn divisors(n i64) []i64 {
mut divs := [i64(1)]
mut divs := [i64(1)]
mut divs2 := []i64{}
mut divs2 := []i64{}
Line 6,557: Line 6,557:
println("\nThe first abundant odd number above one billion is:")
println("\nThe first abundant odd number above one billion is:")
abundant_odd(1_000_000_001, 0, 1, true)
abundant_odd(1_000_000_001, 0, 1, true)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 6,568: Line 6,568:
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
{{libheader|Wren-math}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang=ecmascript>import "/fmt" for Fmt
import "/math" for Int, Nums
import "/math" for Int, Nums
Line 6,603: Line 6,603:
System.print("\nThe first abundant odd number above one billion is:")
System.print("\nThe first abundant odd number above one billion is:")
abundantOdd.call(1e9+1, 0, 1, true)</lang>
abundantOdd.call(1e9+1, 0, 1, true)</syntaxhighlight>


{{out}}
{{out}}
Line 6,643: Line 6,643:
=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
Assemble with tasm and tlink /t
Assemble with tasm and tlink /t
<lang asm> .model tiny
<syntaxhighlight lang=asm> .model tiny
.code
.code
.486
.486
Line 6,714: Line 6,714:
int 29h
int 29h
no30: ret
no30: ret
end start</lang>
end start</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 6,747: Line 6,747:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>int Cnt, Num, Div, Sum, Quot;
<syntaxhighlight lang=XPL0>int Cnt, Num, Div, Sum, Quot;
[Cnt:= 0;
[Cnt:= 0;
Num:= 3; \find odd abundant numbers
Num:= 3; \find odd abundant numbers
Line 6,771: Line 6,771:
Num:= Num+2;
Num:= Num+2;
];
];
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 6,805: Line 6,805:


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>fcn oddAbundants(startAt=3){ //--> iterator
<syntaxhighlight lang=zkl>fcn oddAbundants(startAt=3){ //--> iterator
Walker.zero().tweak(fcn(rn){
Walker.zero().tweak(fcn(rn){
n:=rn.value;
n:=rn.value;
Line 6,818: Line 6,818:
}
}
}.fp(Ref(startAt.isOdd and startAt or startAt+1)))
}.fp(Ref(startAt.isOdd and startAt or startAt+1)))
}</lang>
}</syntaxhighlight>
<lang zkl>fcn oddDivisors(n){ // -->sorted List
<syntaxhighlight lang=zkl>fcn oddDivisors(n){ // -->sorted List
[3.. n.toFloat().sqrt().toInt(), 2].pump(List(1),'wrap(d){
[3.. n.toFloat().sqrt().toInt(), 2].pump(List(1),'wrap(d){
if( (y:=n/d) *d != n) return(Void.Skip);
if( (y:=n/d) *d != n) return(Void.Skip);
Line 6,830: Line 6,830:
println("%6,d: %6,d = %s".fmt(n, ds.sum(0), ds.sort().concat(" + ")))
println("%6,d: %6,d = %s".fmt(n, ds.sum(0), ds.sort().concat(" + ")))
}
}
}</lang>
}</syntaxhighlight>
<lang zkl>oaw:=oddAbundants();
<syntaxhighlight lang=zkl>oaw:=oddAbundants();


println("First 25 abundant odd numbers:");
println("First 25 abundant odd numbers:");
Line 6,840: Line 6,840:


println("\nThe first abundant odd number above one billion is:");
println("\nThe first abundant odd number above one billion is:");
printOAs(oddAbundants(1_000_000_000).next());</lang>
printOAs(oddAbundants(1_000_000_000).next());</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:45ex; font-size:83%">
<pre style="height:45ex; font-size:83%">