-
最大公约数
int measure(int x, int y)
{
int z = y;
while(x%y!=0)
{
z = x%y;
x = y;
y = z;
}
return z;
}
-
实现 pow(x, n) ,即计算 x 的 n 次幂函数(即,xn)
class Solution { public: double Pow(double x,unsigned int n) { double ret = 1; while(n) { if(n & 1 == 1) ret *= x; x *= x; n = n>>1; } return ret; } double myPow(double x, int n) { double ret; bool flag = false; unsigned int m = (unsigned int) n; if(n<0) { m = -m; flag = true; } ret = Pow(x,m); if(flag) ret = 1 / ret; return ret; } };