计算 S = a^n :
S = a * a * a * a......
= ( ( (a^2)^2)^2)......
n = 2^k1 + 2^k2 + 2^k3......
例如: 22 = 16+4+2 22的二进制数为:10110
那么: a^22 = a^16 * a^4 * a^2
int pow(int a, int n)
{
int res = 1;
while (n > 0)
{
if (n&1)
res = res*a; //若二进制最低位为1, 则乘以 x*(2^i)
a = a*a; //将x平方
n >>= 1;
}
return res;
}