Using mod on a big number, such as 600851475143, does not give a correct answer, anyone know why?
print 600851475143 / 2.0
print 600851475143 % 2.0
print 4 / 2.0
print 4 % 2.0
600851475143 / 2.0 = 300425737572.0
600851475143 % 2.0 = 1.0 4 / 2.0 = 2.0 4 % 2.0 = 0.0
I was working on creating my own prime number function and it works fine for smaller开发者_如何学JAVA numbers, but modular seems to break when the numbers get bigger. I'm just messing around with python and the Euler challenge and have been banging my head against a wall for awhile now.
Thank you.
>>> print 600851475143 / 2
300425737571
>>> print 600851475143 % 2
1
>>> 4 / 2
2
>>> 4 % 2
0
Apart from that: your issue has nothing to do with big numbers - it's only about integer operations in Python.
精彩评论