In C/C++ how can I calculate (a^b)%m
where b
does not fit into 64 bits? In other words, is there a way of calculating the above value using b%m
instead of b
?
And is there any algorithm that can compute the above result in O(log(b))
time or O(log(b%m))
time?