From d43ce9e11606a75492abc4036ca6ae76027606e0 Mon Sep 17 00:00:00 2001 From: Ashish Ratnawat Date: Fri, 25 Oct 2019 13:18:02 +0530 Subject: [PATCH] created file for xor of three numbers To make the sum of three numbers equal to the xor of three number --- equalsum_and_XOR.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 equalsum_and_XOR.cpp diff --git a/equalsum_and_XOR.cpp b/equalsum_and_XOR.cpp new file mode 100644 index 0000000..297ce17 --- /dev/null +++ b/equalsum_and_XOR.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; + +// Defining ull to unsigned long long int +typedef unsigned long long int ull; + +// Function to calculate power of 3 +ull calculate(int bit_cnt) +{ + ull res = 1; + while (bit_cnt--) { + res = res * 3; + } + + return res; +} + +// Function to return the count of the +// unset bit ( zeros ) +int unset_bit_count(ull n) +{ + int count = 0; + while (n) { + + // Check the bit is 0 or not + if ((n & 1) == 0) + count++; + // Right shifting ( dividing by 2 ) + n = n >> 1; + } + return count; +} + +// Driver Code +int main() +{ + ull n; + n = 2; + + int count = unset_bit_count(n); + + ull ans = calculate(count); + + cout << ans << endl; + + return 0; +}