求x的y次幂
public class Main {
public static void main(String[] args) {
System.out.println(power(3,18));
}
//求x的y次幂
private static long power(long x, long y){
if ( y == 1)
return x ;
else
{
if (y % 2 == 1)
return x * power(x*x,y/2);
else
return power(x*x,y/2);
}
}
}