File size: 710 Bytes
c4b0eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/**
* 100 - The 3n + 1 problem
*/
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int i, j, auxI, auxJ, max, cycle;
while(cin >> i >> j){
auxI = i;
auxJ = j;
if(i > j) swap(i, j);
max = -1;
while(i <= j){
cycle = 1;
long long int n = i;
while(n != 1){
if(n % 2 == 1) n = 3 * n + 1;
else n /= 2;
cycle++;
}
if(cycle > max) max = cycle;
i++;
}
printf("%d %d %d\n", auxI, auxJ, max);
}
return 0;
}
/**
Sample Input
1 10
100 200
201 210
900 1000
*/
|