On Sun, 12 Dec 1999, Matthew Hiller wrote:
> Is there a good UNIX tool for doing modular arithmetic, short of
> writing snippets of C using libgmp? bc is very slow if you give it
> things like (14^96568) % 99907.
Well, what did you expect?! :)
My general advice: always use higher-level tools when you can and when
they're fast enough. In this case, don't bother writing "snippets of C"
and libgmp when you can write functions in bc.
Try this:
define modex(x,y,m) {
auto i, r;
r = 1;
for (i=0; i<y; i++) {
r = (r * x) % m
}
return(r);
}
modex(14,96568,99907)
That should do what you want. For other operations, write similarly
simple functions. You could even write more general stuff if you wanted
to, though you'd probably hit diminishing returns after a certain point.
Hope that helps. Quick enough answer? ;)
Shawn
This archive was generated by hypermail 2b29 : Wed Apr 27 2005 - 03:30:03 EDT