#include "stdio.h" #include "stdlib.h" #include "vector" using namespace std; int minimum(int c1, int c2) { return (c1 p1; vector p2; while (c1 != 0 || c2 != 0) { if (c1 == 1 && c2 == 1) { printf("1 needs 0 steps, 1 needs 0 steps, they meet at 1\n"); scanf("%d%d",&c1,&c2); continue; } unsigned int sc1 = c1; unsigned int sc2 = c2; p1.clear(); while (c1 != 1) { p1.push_back(c1); if (c1%2 == 0) { c1 = c1/2; } else { c1 = 3*c1+1; } } p1.push_back(c1); p2.clear(); while (c2 != 1) { p2.push_back(c2); if (c2%2 == 0) { c2 = c2/2; } else { c2 = 3*c2+1; } } p2.push_back(c2); unsigned int rozdil = abs(p1.size()-p2.size()); unsigned int prvni = p1.size(); unsigned int druhy = p2.size(); if (p1.size() > p2.size()) { for (unsigned int i=0; i p2.size()) { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n",sc1,prvni,sc2,druhy,p1[rozdil+minimum(prvni,druhy)]); } else { printf("%d needs %d steps, %d needs %d steps, they meet at %d\n",sc1,prvni,sc2,druhy,p2[rozdil+minimum(prvni,druhy)]); } scanf("%d%d",&c1,&c2); } return 0; }