Why is this printing the negative number -147982099 instead of 8462696833 = 600851475143 / 71
import Data.List
smallFactor n = case (elemIndex 0 (map (mod n) [2..])) of
Just x -> x + 2
main = print( quot n (smallFactor n) )
where n = 600851475143
The full output:
$ ghc --make p3; ./p3
[1 of 1] Compiling Main ( p3.hs, p3.o )
Linking p3 ...
-147982099
smallFactor
to work withInteger
types (instead ofInt
which may overflow...). – Interpret