#include #include #include typedef struct ITEM { long long int Value; int nSteps; ITEM() {} ITEM(long long int v, int n): Value(v), nSteps(n) {} int operator < (ITEM const& Item) const {return this->Value < Item.Value;} } ITEM; using namespace std; long long int f(long long int a) { if(a % 2) { return (a * 3) + 1; } else { return a / 2; } } int main() { while(1) { int origa, origb; scanf("%d%d", &origa, &origb); if(!((origa) || (origb))) { break; } long long int a = origa, b = origb; set s1; set s2; if(0) { } else { int nSteps = 0; while(1) { if(s2.find(ITEM(a, 0)) != s2.end()) { set::iterator it = s2.find(ITEM(a, 0)); printf("%d needs %d steps, %d needs %d steps, they meet at %lld\n", origa, nSteps, origb, it->nSteps, a); break; } else if(s1.find(ITEM(a, 0)) == s1.end()) { s1.insert(ITEM(a, nSteps)); } a = f(a); if(s1.find(ITEM(b, 0)) != s1.end()) { set::iterator it = s1.find(ITEM(b, 0)); printf("%d needs %d steps, %d needs %d steps, they meet at %lld\n", origa, it->nSteps, origb, nSteps, b); break; } else if(s2.find(ITEM(b, 0)) == s2.end()) { s2.insert(ITEM(b, nSteps)); } b = f(b); nSteps++; } } } return 0; }