#include #include #include #include std::map aP; std::map bP; int a,aZ,a_step; int b,bZ,b_step; int final; int ooo; 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; //std::map::iterator it2; it=aP.find(a); if(it==aP.end()) { aP.insert(std::make_pair(a,a_step)); } it=bP.find(b); if(it==bP.end()) { bP.insert(std::make_pair(b,b_step)); } 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",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("%d%d",&a,&b); if(a==0 && b==0) break; else magic(); } return 0; }