#include #include #include #include std::map aP; std::map bP; long a,aZ,a_step; long b,bZ,b_step; long final; void magic() { aZ=a; bZ=b; final=aZ; if(a!=b) while(true) { if(a!=1) { if(a%2==0) { a=a/2; } else { a=3*a+1; } a_step++; } if(b!=1) { if(b%2==0) { b=b/2; } else { b=3*b+1; } b_step++; } std::map::iterator it; aP.insert(std::make_pair(a,a_step)); bP.insert(std::make_pair(b,b_step)); //printf("mame %d %d\n",(int)a,(int)b); if(a==bZ) {b_step=0; final=a; break;} if(b==aZ) {a_step=0; final=b; break;} it=bP.find(a); if(it!=bP.end()) {final=a; b_step=it->second; break;} it=aP.find(b); if(it!=aP.end()) {final=b; a_step=it->second; break;} } printf("%d needs %d steps, %d needs %d steps, they meet at %d\n",(int)aZ,(int)a_step,(int)bZ,(int)b_step,(int)final); } int main() { while(true) { aP.clear(); bP.clear(); b=bZ=b_step=a=aZ=a_step=final=0; int i,j; scanf("%d%d",&i,&j); a=i; b=j; if(a==0 && b==0) break; else magic(); } return 0; }