最好的情况是全拆分为3,否则剩余一个2或4也可以。
public class DevideInt {
public static int devidePlus(int n) {
int ans=1;
if(n%3==0) {
int power=n/3;
double d=Math.pow(3,power);
ans=(int)d;
}else if(n%3==1) {
int power=(n-1)/3-1;
double d=Math.pow(3,power);
ans=(int)d*4;
}else {
int power=(n-2)/3-1;
double d=Math.pow(3,power);
ans=(int)d*2;
}
return ans;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(devidePlus(25));
}
}