The 3n + 1 problem
user_6817964
c_cpp
3 years ago
640 B
8
Indexable
#include <iostream>
using namespace std;
main(){
int i, j;
while(cin >> i >> j){
cout << i << " " << j << " ";
if(i > j){
int temp = i;
i = j;
j = temp;
}
int max = 0;
for(int x = i; x <= j; x++){
int sum = 1, k = x;
while(k != 1){
sum++;
if(k % 2 == 1)
k = k * 3 + 1;
else
k /=2;
}
if(sum > max)
max = sum;
}
cout << max << endl;
}
}Editor is loading...