Minimize product of first 2 ^ Kâ €“ 1 Natural Numbers by swapping bits for any pair any number of times | C ++ program for the above approach ; Function to find the minimum positive product after swapping bits at the similar position for any two numbers ; Stores the resultant number ; range / 2 numbers will be 1 and range / 2 numbers will be range - 1 ; Multiply with the final number ; Return the answer ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimumPossibleProduct ( int K ) { int res = 1 ; int range = ( 1 << K ) - 1 ; for ( int i = 0 ; i < K ; i ++ ) { res *= ( range - 1 ) ; } res *= range ; return res ; } int main ( ) { int K = 3 ; cout << minimumPossibleProduct ( K ) ; return 0 ; }