Equal Sum and XOR of three Numbers | Java implementation of the approach ; Function to calculate power of 3 ; Function to return the count of the unset bit ( zeros ) ; Check the bit is 0 or not ; Right shifting ( dividing by 2 ) ; Driver Code
import java . util . * ; class GFG { static long calculate ( int bit_cnt ) { long res = 1 ; while ( bit_cnt -- > 0 ) { res = res * 3 ; } return res ; } static int unset_bit_count ( long n ) { int count = 0 ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) count ++ ; n = n >> 1 ; } return count ; } public static void main ( String [ ] args ) { long n ; n = 2 ; int count = unset_bit_count ( n ) ; long ans = calculate ( count ) ; System . out . println ( ans ) ; } }