/* LittleElephantAndDouble (SRM 597, D2, 250 from Topcoder). James S. Plank Wed Dec 4 11:33:07 EST 2019 This is an O(n^2) solution that naively checks every pair of elements. */ #include #include using namespace std; class LittleElephantAndDouble { public: string getAnswer(vector &A); }; bool check(int x, int y) { if (x > y) return check(y, x); while (x < y) x *= 2; return (x == y); } string LittleElephantAndDouble::getAnswer(vector &A) { size_t i, j; for (i = 0; i < A.size(); i++) { for (j = 0; j < i; j++) { if (!check(A[i], A[j])) return "NO"; } } return "YES"; }