import java.util.*; public class Solution { // 根据数学常识作答,能分成3就分3 public int cutRope (int n) { if(n == 1 || n == 2){ return 1; }else if(n == 3){ return 2; } // write code here int result = 0; int mod = n % 3; if(mod == 0){ result = (int)Math.pow(3,n / 3); }else if(mod == 1){ result = 2 * 2 * (int)Math.pow(3,n / 3 - 1); }else if(mod == 2){ result = 2 * (int)Math.pow(3, n / 3); } return result; } }