Problem
The prime factors of $13195$ are $5$, $7$, $13$ and $29$.
What is the largest prime factor of the number $600851475143$ ?
Haskell Code
Euler_003.hs
module Main where
import Data.List
-- (x:xs)は自然数の列で、小さい方からnを除算をしていく。
-- 剰余が0ならもう一度その同じ数で除算し、
-- そうでないなら次の自然数で除算するという再帰。
factoring n fs (x:xs)
| n == 1 = fs
| (mod n x == 0) = factoring (div n x) (x:fs) (x:xs)
|otherwise = factoring n fs xs
main = print answer
where
answer = maximum $ factoring n [] [2..n]
n = 600851475143
Answer
6**7