سؤال

I'm doing some calculations with large integers in Python and I'm getting some weird results.

>>> 94970389L * 94958913L / 775920493L
11622692L
>>> 94970389L * 94958913L
9018284906627157L
>>> 775920493L * 11622692L
9018284906627156L

Why is there a difference between fourth line and sixth line ? It should be equal.

I'm using Python version 2.7.3 on linux pc 32bits

هل كانت مفيدة؟

المحلول

The remainder of your division is 1:

>>> 94970389L * 94958913L % 775920493L
1L

Remember, division of two integers in Python 2.x is an integer division by default, and the remainder is thrown away.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top