View Single Post
Old 2004-05-08, 02:52   #1
maheshexp
 
May 2004

2510 Posts
Lightbulb New way to Find (X^Y) % M

here i had developed a simple algorithm to calculate (X^Y)%M. i works well and faster than any string manipulated operations.

//(x^y)%m
long r1 = x % m;
// loop upto y - 1, for x ^(y-1)
for (long i = 0; i < y - 1; i++) {
r1 = (r1 * x) % m;
}


hope this works...

mahesh
maheshexp is offline   Reply With Quote