求解
x
n
x^n
xn时 结合二进制进行思考
例如
x
10
x^{10}
x10 就是 1010
x
10
=
x
2
∗
x
8
x^{10}=x^2*x^8
x10=x2∗x8
public static void main(String[] args) {
int n=10;
long x=2,res=1;
while (n>0)
{
if (n%2==1) res*=x;
x*=x;
n/=2;
}
System.out.println(res);
}