![在这里插入图片描述](https://img-blog.csdnimg.cn/20200420180346541.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nNzZG4ubmV0L3FxXzQzMzkwMjM1,size_16,color_FFFFFF,t_70
class Solution {
public int cuttingRope(int n) {
if(n <= 3) return n - 1;
long res=1;
while(n>4){
res*=3;
res=res%1000000007;
n-=3;
}
return (int)(res*n%1000000007);
}
}
一类型问题,主要明白3是最优解,2其次,1最差。
如何得出呢?看这里
class Solution {
public int integerBreak(int n) {
if(n<=3){return n-1;}
int a=1;
while(n>4){
n-=3;
a*=3;
}
return a*n;
}
}