#include #include #include inline int next(int i) { if (i % 2 == 0) return i/2; return 3*i + 1; } int main(int argc, char ** argv) { int first, firstn, secondn, second, firstPos, secondPos, number; std::map firstV, secondV; while(1){ scanf("%d %d", &firstn, &secondn); if (firstn == 0 && secondn == 0) break; firstV.clear(); secondV.clear(); if (firstn == secondn ) { printf("%d needs 0 steps, %d need 0 steps, they meet at %d\n", firstn, firstn, firstn); continue; } first = firstn; second = secondn; firstV[first] = 0; secondV[second] = 0; for(int step = 1;; step++){ first = next(first); second = next(second); if (firstV.find(first) == firstV.end()) firstV[first] = step; if (secondV.find(second) == secondV.end()) secondV[second] = step; firstPos = firstV.find(second) !=firstV.end() ? firstV.find(second)->second : -1; secondPos = secondV.find(first) !=secondV.end() ? secondV.find(first)->second : -1; if ( firstPos != -1 && secondPos != -1) { int better = firstPos > secondPos ? secondPos : firstPos; if (firstPos == better) { number = second; secondPos = step; } else{ number = first; firstPos = step; } break; } else if (firstPos != -1) { number = second; secondPos = step; break; } else if (secondPos != -1) { number = first; firstPos = step; break; } } printf("%d needs %d steps, %d need %d steps, they meet at %d\n", firstn, firstPos, secondn, secondPos, number); } return (0); }