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
|