#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main(){ int n, m, i, j, temp, x, y; int maximum; while(scanf("%d %d", &x, &y) == 2){ cout << x << " " << y; m = max(x, y); n = min(x, y); maximum = 0; for(i = n; i <= m; i++){ int count = 1; j = i; while(j > 1){ if(j % 2 == 0) j = j / 2; else j = (3 * j + 1); count++; } if(count >= maximum) maximum = count; } cout << " " << maximum << endl; } return 0; }
Wednesday, July 2, 2014
UVa - 100 - The 3n + 1 problem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment