Equal Sum and XOR of three Numbers | C ++ implementation of the above 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; typedef unsigned long long int ull ; ull calculate ( int bit_cnt ) { ull res = 1 ; while ( bit_cnt -- ) { res = res * 3 ; } return res ; } int unset_bit_count ( ull n ) { int count = 0 ; while ( n ) { if ( ( n & 1 ) == 0 ) count ++ ; n = n >> 1 ; } return count ; } int main ( ) { ull n ; n = 2 ; int count = unset_bit_count ( n ) ; ull ans = calculate ( count ) ; cout << ans << endl ; return 0 ; }