C # implementation of the approach
using System ; using System . Collections . Generic ; class GFG { static int MAX = 32 ; static long [ ] pow2 = new long [ MAX ] ; static bool [ ] visited = new bool [ MAX ] ; static List < long > ans = new List < long > ( ) ;