Answer the question
In order to leave comments, you need to log in
What is the name of the algorithm?
What is the name of the algorithm and why is there a class template here, why is it ???
template< class T >
int pow_mod(T a, T b, T m) {
T r = 1;
a %= m;
while (b) {
if (b & 1)
r = (r * a) % m;
a = (a * a) % m;
b >>= 1;
}
return r;
}
Answer the question
In order to leave comments, you need to log in
Google template c++
So that the function can take arguments of different types. Instead of overloading function arguments for different types (float, int), a template is used here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question