Python handles only 53 bits of precision for floating point numbers (about 16 decimal places), so using floats that large won't work very well.
Use the modulo operator instead:
>>> (2**80 / float(3)) % 1 # Doesn't work
0.0
>>> 2**80 % 3 # Works
1L
>>> 2**80 % 2 # Works
0L
It's also quite a bit faster than division:
>>> %timeit (2**40 / float(2)) == 0
1000000 loops, best of 3: 224 ns per loop
>>> %timeit 2**40 % 2 == 0
10000000 loops, best of 3: 53.5 ns per loop
If i
is a factor of n
, then n % i == 0
(n
is congruent to 0
modulo i
).