MATDYS - I have a problem with my solution.
It is passing all the sample test cases but not subtask 3. I have also used unsigned long long int.

i have used unsigned long long int. still it is not passing.

@sandeep_007, but it is giving the correct answer on sample test case, i.e.
64 11047805202224836936
and if it is exception so can’t it be solved using bitset

1 Like

have to check your again, didn’t see your code thoroughly. (Sorry!)

@nishant0208, your solution isn’t guaranteed to work when n exceeds 31, but again works for n=64. For example, suppose the input is
50 1099511627776
Here 1099511627776 is 240.
So the bitset looks like
After reversing, it becomes
Now what you want to do is transfer the first n bits to the end, like so


But your code does something different. The 1 is at position 40. Because it swaps the bits at i and i+64-n, when i=26, it will swap with 40. So you get this instead.


The solution is quite simple… just use a bitset of length longer than twice the max value of n. So if you just use bitsets of length 128 or greater, it should work fine :smiley:

Thank You so much @meooow. I got your point. Now it works :slight_smile: