import java.util.*; public class Solution { // 尽可能多的分为2和3,有3分3,没3分2,同时要排除1 public int cutRope (int n) { // write code here int num_three = 0; if(n % 3 == 0){ num_three = n / 3; return (int) Math.pow(3,num_three); // 当余1时,这个1可以与一个3组成两个2,所以*4 }else if(n % 3 == 1){ num_three = n / 3 - 1; return (int) Math.pow(3,num_three) * 4; }else if(n % 3 == 2){ num_three = n / 3; return (int) Math.pow(3,num_three) * 2; } return 0; } }