How to resolve the algorithm Abundant odd numbers step by step in the AutoHotkey programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abundant odd numbers step by step in the AutoHotkey programming language
Table of Contents
Problem Statement
An Abundant number is a number n for which the sum of divisors σ(n) > 2n, or, equivalently, the sum of proper divisors (or aliquot sum) s(n) > n.
12 is abundant, it has the proper divisors 1,2,3,4 & 6 which sum to 16 ( > 12 or n); or alternately, has the sigma sum of 1,2,3,4,6 & 12 which sum to 28 ( > 24 or 2n).
Abundant numbers are common, though even abundant numbers seem to be much more common than odd abundant numbers. To make things more interesting, this task is specifically about finding odd abundant numbers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Abundant odd numbers step by step in the AutoHotkey programming language
Source code in the autohotkey programming language
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
}
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
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the AWK programming language
You may also check:How to resolve the algorithm Horizontal sundial calculations step by step in the OCaml programming language
You may also check:How to resolve the algorithm Euler method step by step in the zkl programming language
You may also check:How to resolve the algorithm Generate random chess position step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Infinity step by step in the Scheme programming language