#include #include #include int main(){ char * postupA = (char *)malloc(100000000); char * postupB = (char *)malloc(100000000); int a, b; scanf("%d%d", &a, &b ); while (a != 0){ int countA = 0, countB = 0; int tmpA = a, tmpB = b; strcpy(postupA,""); strcpy(postupB,""); if ( a == b ){ printf("%d needs 0 steps, %d needs 0 steps, they meet at %d\n", a, b, a); scanf("%d%d", &a, &b ); continue; } while ( tmpA != 1 ){ if( tmpA % 2 == 0 ){ tmpA /= 2; postupA = strcat( postupA, "0" ); } else{ tmpA = 3 * tmpA + 1; postupA = strcat( postupA, "1" ); } countA++; } while ( tmpB != 1 ){ if( tmpB % 2 == 0 ){ tmpB /= 2; postupB = strcat( postupB, "0" ); } else{ tmpB = 3 * tmpB + 1; postupB = strcat( postupB, "1" ); } countB++; } while ( countA > 0 && countB > 0 ){ if ( postupA[countA - 1] == postupB[countB - 1] ){ if ( postupA[countA - 1] == '0' ){ tmpA *= 2; } else{ tmpA = (tmpA - 1) / 3; } countA--; countB--; } else break; } printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", a, countA, b, countB, tmpA); scanf("%d%d", &a, &b ); } return 0; }