SHKNUM partially solved

I simply used brute force to solve the problem.But my all test cases do not pass.I have tried this code for large numbers like 10^8,10^9,etc in online ide and my code gives right answer.Also,I havent optimized the for loops but still time complexity shouldn’t be the issue.(31 x 31 x 10^5).And if TLE is a problem,then judge should show TLE and not wrong answer.

Here is the link to my approach.

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

Please tell the failing test cases.Any help is highly appreciated.

if(N==1)
diff=1;
I think, Here you are wrong as because for n=1, m should be 3 = 2^0+2^1 .
And according to your code m will be 0 or 2 where 0 can’t be represented as 2^x+2^y and 2 = 2^0+2^0 but (x != y see problem statement). So for n=1 diff should be 2.