#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int algo(int n){
int count = 1;
while(n != 1){
if(n % 2 == 1){
n = n * 3 + 1;
count++;
}
else{
n/= 2;
count++;
}
}
return count;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, ans = 0;
while(cin >> a >> b){
cout << a << ' ' << b << ' ';
while(a <= b){
ans = max(ans, algo(a));
a++;
}
cout << ans << endl;
}
return 0;
}
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int algo(int n){
int count = 1;
while(n != 1){
if(n % 2 == 1){
n = n * 3 + 1;
count++;
}
else{
n/= 2;
count++;
}
}
return count;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b, ans = 0;
while(cin >> a >> b){
cout << a << ' ' << b << ' ';
while(a <= b){
ans = max(ans, algo(a));
a++;
}
cout << ans << endl;
}
return 0;
}
1. 你的ans沒有在迴圈重設為0
2. a有可能大於b