How to resolve the algorithm Abundant odd numbers step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Abundant odd numbers step by step in the F# 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 F# programming language
Source code in the fsharp programming language
// 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
You may also check:How to resolve the algorithm Collections step by step in the Objeck programming language
You may also check:How to resolve the algorithm Compound data type step by step in the Rust programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the K programming language
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the C# programming language
You may also check:How to resolve the algorithm Sleep step by step in the Swift programming language