1、计算 x(实数) 的 n(整数) 次方 ,O(logn) codes: import java.util.Scanner; public class Power { public static double power(double x, int n){ if(n==0) return 1; if(n%2==0){ // even double temp= power(x,n/2); return temp*temp; } else{ // odd double temp=power(x,(n-1)/2); return temp*temp*x; } } public static void main(String[] args) { Scanner in=new Scanner(System.in); while(true) { double x=in.nextDouble(); int n=in.nextInt(); System.out.println(power(x,n)); System.out.println(Math.pow(x, n)); } } } 2、求Fibonacci数,O(logN),矩阵相乘 codes: import java.util.Scanner; //矩阵 class Matrix{ //初始为基本矩阵 public int [][] elem={{1,1},{1,0}}; //矩阵相乘,修改本身 public Matrix multiply(Matrix m2){ int temp[][]=