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

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.

1

64 11047805202224836936

and if it is exception so can’t it be solved using bitset

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 2^{40}.

So the bitset looks like

`0000000000000000000000010000000000000000000000000000000000000000`

After reversing, it becomes

`0000000000000000000000000000000000000000100000000000000000000000`

Now what you want to do is transfer the first n bits to the end, like so

```
[00000000000000000000000000000000000000001000000000]00000000000000
```

`00000000000000[00000000000000000000000000000000000000001000000000]`

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.

```
00000000000000[00000000000010000000000000000000000000000000000000]
```

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