#include #include #include int main(void){ int max = 200000000; int a, b; int *pole1, *pole2; int bigint = 0; pole1 = (int *) malloc(max*sizeof(int)); pole2 = (int *) malloc(max*sizeof(int)); memset(pole1, 0, sizeof(pole1)); while (1==1) { scanf("%d %d", &a, &b); if ((a == 0) && (b == 0)) return 0; memset(pole2, 0, sizeof(pole2)); int hladaj = a; int krokA = 1, krokB = 1; while (1==1){ if (hladaj == 1) break; if (pole1[hladaj] == 0){ if (hladaj%2 == 0) pole1[hladaj] = hladaj / 2; else pole1[hladaj] = hladaj *3+1; } pole2[hladaj] = krokA; hladaj = pole1[hladaj]; if (bigint < hladaj) bigint = hladaj; krokA++; } hladaj = b; while (1 == 1){ if (hladaj == 1) break; if (pole2[hladaj] != 0) break; if (pole1[hladaj] == 0){ if (hladaj%2 == 0) pole1[hladaj] = hladaj / 2; else pole1[hladaj] = hladaj *3+1; } hladaj = pole1[hladaj]; if (bigint < hladaj) bigint = hladaj; krokB++; } printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", a, pole2[hladaj]-1, b, krokB-1, hladaj); printf("%d\n", bigint); } }