#include #include using namespace std; int main() { int a, b; int A, B; while ( 1 ) { scanf("%d %d", &a, &b); A = a; B = b; if ( a == 0 && b == 0 ) return 0; map first; map second; first.insert(make_pair(a, 0)); second.insert(make_pair(b, 0)); int counter = 1; while ( 1 ) { if ( a != 1 ) { if ( a % 2 == 0 ) a /= 2; else a = 3*a+1; map ::iterator it = second.find(a); if ( it != second.end() ) { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", A, counter, B, it->second, a); break; } } if ( b != 1 ) { if ( b % 2 == 0 ) b /= 2; else b = 3*b+1; map ::iterator it = first.find(b); if ( it != first.end() ) { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", A, counter, B, it->second, b); break; } } if ( a != 1 ) first.insert(make_pair(a, counter)); if ( b != 1 ) second.insert(make_pair(b, counter)); ++counter; } } return 0; }