Number of pairs whose product is a power of 2 | C # program for the above approach ; Function to count pairs having product equal to a power of 2 ; Stores count of array elements which are power of 2 ; If array element contains only one set bit ; Increase count of powers of 2 ; Count required number of pairs ; Print the required number of pairs ; Driver Code ; Given array ; Size of the array ; Function call
using System ; using System . Linq ; class GFG { static void countPairs ( int [ ] arr , int N ) { int countPowerof2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( Convert . ToString ( arr [ i ] , 2 ) ) . Count ( f => ( f == '1' ) ) == 1 ) countPowerof2 ++ ; } int desiredPairs = ( countPowerof2 * ( countPowerof2 - 1 ) ) / 2 ; Console . WriteLine ( desiredPairs + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 7 , 2 } ; int N = arr . Length ; countPairs ( arr , N ) ; } }