#include #include #include #include std::map aP; std::map bP; long long a,aZ,a_step; long long b,bZ,b_step; long 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("%lld needs %lld steps, %lld needs %lld steps, they meet at %lld\n",aZ,a_step,bZ,b_step,final); } int main() { while(true) { aP.clear(); bP.clear(); b=bZ=b_step=a=aZ=a_step=final=0; scanf("%lld%lld",&a,&b); if(a==0 && b==0) break; else magic(); } return 0; }