个别算法详解
作者:互联网
power
template <class _Tp, class _Integer, class _MonoidOperation>
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
{
if (__n == 0)
return identity_element(__opr);
else {
while ((__n & 1) == 0) {
__n >>= 1;
__x = __opr(__x, __x);
}
_Tp __result = __x;
__n >>= 1;
while (__n != 0) {
__x = __opr(__x, __x);
if ((__n & 1) != 0)
__result = __opr(__result, __x);
__n >>= 1;
}
return __result;
}
}
\({2^{\rm{n}}}{\rm{ = }}{2^{(n/2)}}*{2^{(n/2)}}\;\;(n{\rm{\% }}2{\rm{ = = }}0)\)
标签:__,return,opr,Tp,算法,详解,result,个别,rm 来源: https://www.cnblogs.com/xiaojianliu/p/12628875.html