代码如下:
#include<bits/stdc++.h>
using namespace std;
int f(int x){
if(x==1) return 1;
else if(x%2) return f(3*x+1)+1;
else return f(x/2)+1;
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=0){
int maxn=0xc0c0c0c0;
for(int i=min(n,m);i<=max(n,m);i++){
maxn=max(maxn,f(i));
}
cout<<n<<" "<<m<<" "<<maxn<<"\n";
}
return 0;
}
“感觉”和题解没有什么区别,望过路的仙人指路