#include #include #include #include #include #include using namespace std; struct comb { int num; int iter; }; struct classcomp { bool operator() (const comb& lhs, const comb& rhs) { return lhs.num < rhs.num; } }; inline void next(struct comb& in) { if(in.num % 2 == 0) { in.num = in.num / 2; } else { in.num = 3 * in.num + 1; } in.iter++; } int main() { int x1; int x2; // int cislo; int i; int vysl1; //int vysl2; int orig1; int orig2; // set mnozina; // set::iterator it; vector mnozina; vector iteracie; while(1) { struct comb test; test.iter = 0; mnozina.clear(); scanf("%d %d", &x1, &x2); orig1 = x1; orig2 = x2; if((x1 == 0) && (x2 == 0)) { break; } /* if(x1*3 <= x2/2) { test.num = x1; x1 = x2; } else { test.num = x2; x2 = x1; } */ test.num = x1; while(test.num != 1) { // mnozina.insert(test); //printf("pushing %d %d\n", test.num, test.iter); mnozina.push_back(test.num); iteracie.push_back(test.iter); next(test); } test.num = x2; test.iter = 0; // printf("faza 2\n"); while(1) { //it = mnozina.find(test); for(i = 0; i < (int) mnozina.size(); i++) { // printf("trying %d %d\n", mnozina[i], test.num); if(test.num == mnozina[i]) { vysl1 = i; goto end; } } next(test); } end: printf("%d needs %d steps, %d needs %d steps, they meet at %d\n", x1, vysl1, x2, test.iter, test.num); } return 0; }