Chowla numbers: Difference between revisions

m
Line 1,523:
import Data.List (intercalate)
 
sumFactors :: [(Prime IntegerWord, Word)] -> IntegerWord
sumFactors = product . map f
where f (n, count) = foldr (\p s -> s + unPrime n^p) 1 [1..count]
 
chowla :: IntegerWord -> IntegerWord
chowla 1 = 0
chowla n = sumFactors (factorise n) - 1 - n
 
chowlaPrime :: IntegerWord -> Bool
chowlaPrime 1 = False
chowlaPrime n = chowla n == 0
 
chowlaPerfectNum :: IntegerWord -> Bool
chowlaPerfectNum 1 = False
chowlaPerfectNum n = chowla n == pred n
 
chowlaPrimes :: [IntegerWord] -> [(String, String)]
chowlaPrimes = go 0 [1..]
where
Anonymous user