0
$\begingroup$

is there another way to calculate a*a mod m mathematically? m is larger than a so (a%m)*(a%m) %m doesn't do anything, but a*a is large enough to overflow.

  • 0
    Which sizes are we talking about here? What kind of arithmetic do you have access to?2012-04-11
  • 0
    Anything doable in C++2012-04-11
  • 0
    I assume that you're already using `long` rather than `int` in your code? If so, then you should use the GMP bignum types for arbitrary precision arithmetic: http://gmplib.org/2012-04-11
  • 0
    I'm using int64's -- unfortunately I had a very difficult time getting GMP to work2012-04-11

1 Answers 1