what is wrong with the logic?


You have used pow function which returns a double value
here is the syntax pow
so instead either you use powl or better run a loop and multiple by 2 by bitshitft(x<<1) till l is less than n

The approach you used here is wrong! log2() factor will not yield the right result for some critical test cases. Here is right approach. I just modify your code a little bit.


  [1]: https://www.codechef.com/viewsolution/13141077
1 Like

could you specify in which critical test cases my code fails…
i still couldn’t get the problem with my logic.

The value of n is very large so it’s hard to debug which test case it has been failing!

@bansal1232 is right. The value is too large. I tried for the cases where I can figure answer out manually, it worked on the small ones, However, its not feasible to check on very large test cases.

But yes, it doesn’t mean that its impossible to check for larger values. But it will take effort, LOTS OF IT. If you REALLY want the test case where u are failing, take a correct program, input values of the range/points where you suspect your program to fail and match the output of the correct program and your program. But as I said, its not a “feasible” way as you are doing a hit and trial for test cases. This procedure requires lots of time, and it will only give you the test case (meaning, may not clear confusion as such why its failing, as it only gives value of N).

It might take less time if you’re experienced in finding the corner cases, else I will say its usually not worth the time. But yes, just so you know, this way exists too (might help in future debugging).

(PS: Lol, I wanted to make it a comment…but limits XD)


Can use fast modulo exponentiation…