#include #include using namespace std; int num (const int &x){ if ((x%2) == 0){ return (x/2); } else { return (3*x +1); } } int search ( int x, int y, int &len_a, int &len_b, int &val){ int tmpY =y; int i=0; int j=0; while (1){ if (x == 1) { len_a = i; len_b =j; break;} y = tmpY; j=0; while (1){ if (x==y){ len_a = i; len_b = j; val = x; return 1; } else if (y == 1){ break; } j++; y = num (y); } i++; x = num(x); } return -1; } int main (int argc, char ** argv){ while (1){ int x=0; int y=0; int len_x=0; int len_y=0; scanf ("%d %d",&x,&y); if ((x==0)&&(y==0)){ break; } if (x == y){ printf("%d needs 0 steps, %d needs 0 steps, they meet at %d\n", x,y,x); continue;; } int val=0; if (search (x,y,len_x,len_y,val) == -1){ printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", x,len_x,y,0,y); } else { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", x,len_x,y,len_y,val); } } return (0); }