Skip to content

Instantly share code, notes, and snippets.

@sleepynate
Created September 3, 2010 01:26
Show Gist options
  • Save sleepynate/563257 to your computer and use it in GitHub Desktop.
Save sleepynate/563257 to your computer and use it in GitHub Desktop.
{-
- Project Euler Problem 3
- Solution by nathan dotz - nathan (period) dotz (at sign) gmail (period) com
-
- What is the largest prime factor of the number 600851475143 ?
-}
bignum = 600851475143
divisors = [x|x<-[3,5..(floor(sqrt(fromIntegral(bignum))) `div` 6)], bignum`mod`x==0 ]
answer = last ([ x | x <- divisors, x> 1 && (all (\n -> x `mod` n /= 0 ) $ takeWhile (\n -> n*n <= x) [2..]) ])
main = putStrLn $ "The largest prime factor of " ++ show bignum ++ " is " ++ show answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment