MATDYS - Editorial

Whats wrong with my code? Getting wrong answer on test 3 subtask 3.

https://www.codechef.com/viewsolution/15133990

overflow issues…didn’t you check 2nd sample case given ??

Is n’t the Pseudo Code given wrong?

@ayushgoyal1703, No. You can check my solution(editorialist) as well.

Subtask - 2, 3 (Author’s Solution)

Let us try to find the binary representation of K
and the final answer and try to spot some observations based on it. (Assume below that all binary representations are N

bit long).

Let N=3

Below is the table :

    K               ANS
    000             000
    001             100
    010             010
    011             110
    100             001
    101             101
    110             011
    111             111

Do you spot the relationship between the two of them? Yes, the answer is simply the reverse of K

in binary representation.

Thus, we can simply find the binary representation of K
. Then try to construct the answer from the reverse of the binary representation found.

Can someone provide me an implementation of this approach ?? Thanks in advance :slight_smile:

Is this the implementation of the above approach ??

That’s reversing the binary representation. And you would usually use << operator to get a power of 2.

There is even a shorter way to do this. :slight_smile: https://www.codechef.com/viewsolution/15156758

Can someone explain the author’s solution in details ?How he arrived at it.

Thanks in Advance