The prime factors of 13195 are 5, 7, 13 and 29.My response:
What is the largest prime factor of the number 600851475143 ?
a=600851475143q=head$reverse$filter p$filter(\x->round a`mod`x==0)[1..round$sqrt a] p n=let c=round$sqrt$(fromIntegral::Integer->Double) n in all(\x->n`mod`x/=0)[2..c]171 characters.
Haskell killed me here. That GIGANTIC cast is unfortunately necessary, as far as I can tell.
Ruby version! 67 characters.
ReplyDeletex=600851475143;(2..x).each{|i|((p x;break;)if x==i;x/=i;)if x%i==0}
Nice. This might be why no one uses Haskell.
ReplyDelete