Search code examples
number-theory

How to compute the remainder of a very large number (string with 1 mi digits) in the division by 1500


I'm wondering if there is a trick with number theory to compute this remainder without need to implement a BigInt division algorithm.


Solution

  • Haha, it's easy!

    I can iterate over all digits, adding each parcel... Using the properties:

    1) (a+b) mod c = (a mod c + b mod c) mod c

    2) (a*b) mod c = (a mod c * b mod c) mod c

    The power of ten can be increased mod 1500 each step.