C ++ implementation of the approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long int NEW_LINE #define MAX  32 NEW_LINE ll pow2 [ MAX ] ; bool visited [ MAX ] ; vector < int > ans ;