@@ -1,4 +1,13 @@
|
||||
module Lib where
|
||||
module Lib (fib, primeFactors) where
|
||||
|
||||
fib :: [Integer]
|
||||
fib = 1 : 2 : zipWith (+) fib (tail fib)
|
||||
|
||||
primeFactors :: Integer -> [Integer]
|
||||
primeFactors n = genPrimeFactors n 2
|
||||
where
|
||||
genPrimeFactors :: Integer -> Integer -> [Integer]
|
||||
genPrimeFactors n c
|
||||
| c == n = [n]
|
||||
| mod n c /= 0 = genPrimeFactors n (c + 1)
|
||||
| otherwise = c : genPrimeFactors (div n c) c
|
||||
|
7
haskell/p3.hs
Normal file
7
haskell/p3.hs
Normal file
@@ -0,0 +1,7 @@
|
||||
import Lib (primeFactors)
|
||||
|
||||
main :: IO ()
|
||||
main = putStr $ show solve
|
||||
|
||||
solve :: Integer
|
||||
solve = last $ primeFactors 600851475143
|
Reference in New Issue
Block a user