代码:
#include <iostream>
using namespace std;
int mem[10005];
int i,j;
long long f(int x,int t){
while(1){
if(x==1) return t;
if((x%2)==1){
x=3*x+1;
t++;
}
else {
x/=2;
t++;
}
}
}
int main() {
while(cin>>i>>j){
cout<<i<<" "<<j<<" ";
if(i>j) swap(i,j);
int ans=-1;
for(int r=i;r<=j;r++){
if(mem[r]!=0){
if(mem[r]>ans) ans=mem[r];
}
else {
int temp=f(r,1);
if(temp>ans) ans=temp;
mem[r]=temp;
}
}
cout<<ans<<"\n";
}
return 0;
}
试了三次都是RE,头文件也改过,还是不行。