java实现幂运算,例如5的20次幂(不允许用Math等系统函数),注意临界值。请问这个怎么写?
//求m的n次幂, 不使用Math等系统函数
public static BigInteger ss(int m,int n){
BigInteger result=BigInteger.valueOf(1);
int i=0;
while(i<n){
result=result.multiply(BigInteger.valueOf(m));
i++;
}
return result;
}
可以用循环,这个不大好。
用移位运算吧:long mi = 2 <<19;