Modulus of a big number by a big number.

1.6k Views Asked by At

I'm trying to perform the following calculation:

$$ a\pmod m $$

where both $a$ and $m$ are numbers larger than $32$ bits. However, I'm only able to perform calculations on $32$ bit numbers.

So I was wondering if there is a way to compute arbitrary precision modulo.

1

There are 1 best solutions below

0
On

The most simple way is using Python 2.5+ or Python 3.0+.

Just perform standard math operations and any number which exceeds the boundaries of 32-bit math will be automatically and transparently converted to a bignum.

Moreover, Python is an interpreted language so you may use it as a calculator - just write an expression an press Enter to see the result.

Modulo in Python is represented by the operator %.

Example:

>>> 999999999999999999999999999999 % 333333333333333333333

gives the result

999999999