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
Negative numbers are used to describe values on a scale that goes below zero, such as the Celsius and Fahrenheit scales for temperature. The laws of arithmetic for negative numbers ensure that the common-sense idea of an opposite is reflected in arithmetic.
Because you are telling it a negative number (assuming you are using a 32 bit GHC).
where n = 600851475143 -- n = -443946297
notice:
Prelude Data.Int> 600851475143 :: Int32
-443946297
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With