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.
i don't know about C++ but buddy in C, if you are using unsigned long long type variable while doing operations with constants explicitly mention the type (though automatic type conversion happens but to be on safe side) do use proper SUFFIX representing the type of constant you are using.
for ex , x = n & 1 ----> x = n & 1ULL (because n is unsigned long long)
(x == 0) ---> (x == 0ULL)
and finally i compiled your code this power function is creating an issue,
remember whenever power of 2 is to be calculated it can be done by simply left shifting 1 to those number of bits
therefore next time instead of using
(2,exponent) ---- > (1ULL << exponent)
Sum vs XOR
You are viewing a single comment's thread. Return to all comments →
i don't know about C++ but buddy in C, if you are using unsigned long long type variable while doing operations with constants explicitly mention the type (though automatic type conversion happens but to be on safe side) do use proper SUFFIX representing the type of constant you are using.
for ex , x = n & 1 ----> x = n & 1ULL (because n is unsigned long long)
(x == 0) ---> (x == 0ULL)
and finally i compiled your code this power function is creating an issue,
remember whenever power of 2 is to be calculated it can be done by simply left shifting 1 to those number of bits
therefore next time instead of using (2,exponent) ---- > (1ULL << exponent)