#include #include unsigned long compute(unsigned long a) { if(a % 2 == 0){ //parne return a/2; } else // neparne return (3*a)+1; } int main() { int SIZE = 50000; int a,b; unsigned long sa[SIZE], sb[SIZE]; while(scanf("%d %d", &a, &b)) { if(a == 0 && b == 0) break; for(int i = 0; i < SIZE; i++) { sa[i] = -1; sb[i] = -1; } sa[0] = a; sb[0] = b; int i = 0; while(i < SIZE && sa[i] != 1) { sa[i+1] = compute(sa[i]); if(sa[i+1] == 1) break; i++; } i = 0; while(i < SIZE && sb[i] != 1) { sb[i+1] = compute(sb[i]); if(sb[i+1] == 1) break; i++; } bool end = false; for(int i = 0; i < SIZE; i++) { for(int j = 0; j < SIZE; j++) { if(sa[i] == sb[j]) { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", a, i, b, j, (int)sa[i] ); end = true; break; } } if(end == true) break; } } return 0; }