Count unordered pairs ( i , j ) such that product of a [ i ] and a [ j ] is power of two | C # program to Count unordered pairs ( i , j ) in array such that product of a [ i ] and a [ j ] can be expressed as power of two ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Function to Count unordered pairs ; is a number can be expressed as power of two ; count total number of unordered pairs ; Driver code
using System ; public class GFG { static bool isPowerOfTwo ( int x ) { return ( x > 0 && ( ! ( ( x & ( x - 1 ) ) > 0 ) ) ) ; } static void Count_pairs ( int [ ] a , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPowerOfTwo ( a [ i ] ) ) count ++ ; } int ans = ( count * ( count - 1 ) ) / 2 ; Console . WriteLine ( ans ) ; } static public void Main ( ) { int [ ] a = { 2 , 5 , 8 , 16 , 128 } ; int n = a . Length ; Count_pairs ( a , n ) ; } }