We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
longsumXor(longn){if(n==0){return1;}intnum_bits=std::floor(std::log2(n));intnum_one_bits=__builtin_popcountl(n)-1;// -1 excludes highest power of 2intnum_zero_bits=num_bits-num_one_bits;// # of ways of choosing num_zero_bitsreturn1L<<num_zero_bits;// pow(2, num_zero_bits)}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sum vs XOR
You are viewing a single comment's thread. Return to all comments →
C++: