prefix [ i ] is going to store the number of elements which are a power of two till i ( including i ) .
static int [ ] prefix = new int [ MAX + 1 ] ; static boolean isPowerOfTwo ( int x ) { if ( x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ) return true ; return false ; }