最大公约数和快速幂运算
作者:互联网
-
最大公约数
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; } };
标签:return,运算,int,double,unsigned,ret,x%,最大公约数,快速 来源: https://blog.csdn.net/LHB199802/article/details/119082426