Bitwise Tuples, from June challenge

Solution: 47853116 | CodeChef

Bitwise Tuples | CodeChef

the solution seems perfect, with all the relevant long datatypes, working for the given inputs.
it’s a pretty direct solution, using combinatorics, 2^(n)-1=x all the possible cases for one column (of nXm grid of 0’s and 1’s), to have atleast one “0” in it…that bitwise AND for that place(column) can be zero…there are m columns…so total possibilities is x^m.

i thought of all the cases and everything, still it gives wrong answer…its the most direct and simplest solution.

do help ,if anyone has any idea regarding this…thanks

I think you need to use binary exponentiation: Modular Exponentiation (Power in Modular Arithmetic) - GeeksforGeeks
built-in pow function gives wrong values when u convert it to int/ll since it returns double

1 Like

the value i convert from double to integer, is a natural no. only no? its value should not change after conversion to integer.
i ran the give ques- inputs also through this code, and got the relevant outputs.
i think its creating problems for some very heavy numbers, but idk why.

Conversion to integer truncates the double value. You lose the numbers after the decimal point instead of rounding it up.

but there should be no numbers after the decimal point no?..just zeros…so truncating should not be a problem right?..since its a natural number only

I’m guessing binary calculations are weird. I’m just telling you what I’ve experienced.

yea i got ur point…when i saw the answers , everyone had used that binary exponentiation method only, that u suggested…so i guess learning and using that should be the way ahead.
was stuck on this for a long time…thanks alot for help…much appreciated <3

1 Like