#include #include #include using namespace std; unsigned long computeCycles(unsigned long n); main() { unsigned long i; unsigned long j; while(true) { cin >> i; if(cin.eof()) break; cin >> j; unsigned long max = computeCycles(i); // Swap i and j if i > j bool swapped = false; if(j < i) { unsigned long temp = i; i = j; j = temp; swapped = true; } for(unsigned long k = i+1; k <= j; k++) { // Calculate the cycles for k unsigned long newMax = computeCycles(k); if(newMax > max) max = newMax; } // Output max, switch the order if i and j were swapped earlier if(!swapped) { cout << i << " " << j << " " << max << endl; } else { cout << j << " " << i << " " << max << endl; } } } unsigned long computeCycles(unsigned long n) { unsigned long count = 0; while(n != 1) { // If n is even if(n%2 == 0) { n /= 2; } // If n is odd else { n *= 3; n++; } count++; } return count + 1; }