Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The prime factors of 13195 are 5, 7, 13 and 29. What is the largest
- -- prime factor of the number 600851475143?
- divisorGenerator :: Integral a => a -> a -> a
- divisorGenerator a b = divisibilityCheck a (div a (div a b + 1))
- divisibilityCheck :: Integral a => a -> a -> a
- divisibilityCheck a b = if mod a b == 0 then primeCheck a b else limitCheck a b
- limitCheck :: Integral a => a -> a -> a
- limitCheck a b = if b > 1 then divisorGenerator a b else b
- primeCheck :: Integral a => a -> a -> a
- primeCheck a b = if null [c | c <- [2 .. div b 2], mod b c == 0] then b else limitCheck a b
- initializer :: Integral a => a -> a
- initializer a = limitCheck a (div a 2)
- main :: IO ()
- main = print $ initializer 600851475143
- -- 6857
- -- real 0m1,211s
- -- user 0m1,202s
- -- sys 0m0,008s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement