Abundant odd numbers: Difference between revisions
m
→{{header|Haskell}}: Tidied the Data.Numbers.Primes version – pruned out redundant import.
m (→{{header|AppleScript}}: Minor change to aliquotSum() handler.) |
m (→{{header|Haskell}}: Tidied the Data.Numbers.Primes version – pruned out redundant import.) |
||
Line 2,864:
Or, importing Data.Numbers.Primes (and significantly faster):
<lang haskell>import Data.
import Data.
abundantTuple :: Int -> [(Int, Int)]
abundantTuple n =
in [(n, x) |
divisorSum :: Int -> Int
Line 2,882 ⟶ 2,879:
foldr --
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1]
. primeFactors
main :: IO ()
main = do
putStrLn "First 25 abundant odd numbers with their divisor sums:"
mapM_ print $ take 25 ([1, 3 ..] >>= abundantTuple)
--
putStrLn "\n1000th odd abundant number with its divisor sum:"
print $ ([1, 3 ..] >>= abundantTuple) !! 999
--
putStrLn "\nFirst odd abundant number over 10^9, with its divisor sum:"
let billion = 10 ^ 9 :: Int
print $ head ([1 + billion, 3 + billion ..] >>= abundantTuple)</lang>
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
|