#include #include #include #include #include #include #include #include using namespace std; #define EPS 1e-12 typedef long long LL; LL xx[1042], yy[1042]; void steps(LL x, LL arr[]) { int cnt = 0; while (x != 1) { arr[cnt++] = x; if (x%2) { x = 3*x + 1; } else { x /= 2; } } arr[cnt] = 1; } int main() { LL x, y; scanf("%Ld %Ld\n", &x, &y); while (x) { steps(x, xx); steps(y, yy); int xc = 0; while (1) { int yc = 0; while (yy[yc] != xx[xc] && yy[yc] != 1) ++yc; if (yy[yc] == xx[xc]) { printf("%Ld needs %d steps, %Ld needs %d steps, they meet at %Ld\n", x, xc, y, yc, xx[xc]); break; } ++xc; } scanf("%Ld %Ld\n", &x, &y); } }