3
$\begingroup$

I'm looking for solution to a problem to calculate modulo of very large number that can contain 25000 digits or less (n) with 10 digit number (m). ( n % m ) ?

Pointer to appropriate theory resource is also welcome.

Thanks

  • 1
    If I had to guess, the big number is obtained by exponentiating something, in which case the most efficient course of action is to keep reducing modulo $m$ while computing $n$ in the first place!2012-11-04

1 Answers 1

4

As small as your modulus is, I don't think you can do significantly better than ordinary long division (typically done in base $2^{64}$) to compute the remainder.

However, you can optimize the individual steps; e.g. by using an algorithm like Barrett reduction to obtain the remainder of a 2 digit x 1 digit remainder calculation.

Writing efficient (or even simply correct) division code is a very irritating task; unless you really, really like this sort of programming or are using a specialized algorithm for a very special case, you are certainly better off with a good (or even just decent) bignum package.