问文心一言——讲解C++代码:quickPow
问:讲解以下C++代码
点击查看代码
template <typename T>
T quickPow(T a, int n) {
T res = 1;
while (n > 0) {
if (n % 2 == 1) {
res = res * a;
}
a = a * a;
n /= 2;
}
return res;
}
答:
橘子Jane
问:讲解以下C++代码
template <typename T>
T quickPow(T a, int n) {
T res = 1;
while (n > 0) {
if (n % 2 == 1) {
res = res * a;
}
a = a * a;
n /= 2;
}
return res;
}
答: