http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
What is the time complexity of the right to left method in modular exponentiation?
is it O(1) because we are going through the binary representation of e which is constant time? assuming e is a 32-bit integer
int mod(int b, int e, int m) {
b = b % m;
int result = 1;
while (e) {
if (e % 2 == 1) {
result = (result * b) % m;
}
b = (b * b) % m;
e >>= 1;
}
return result;
}