class Solution {
public:
int maxProductAfterCutting(int length) {
if(length==1) return 1;
if(length==2) return 1;
if(length==3) return 2;
if(length==4) return 4;
if(length%3==1){
int sum=1;
int p=length/3-1;
int q=length%3+1;
for(int i=1;i<=p;i) sum*=3;
for(int i=1;i<=q;i) sum=2;
return sum;
}else{
int sum=1;
int p=length%3;
if(p==0) p=1;
int q=length/3;
for(int i=1;i<=q;i++) sum=3;
return sum*p;
}
}
};