Can someone explain me why this solution is resulting in wrong answer

Problem link

My solution link
https://www.codechef.com/viewsolution/79682912

It should be (n+1). You are taking current number which is wrong just dry run that code you will get to know.

thanks
But i did dry run and try a few of my own test cases and am getting the correct answer.
Is not doing %(n+1) or (%n)-1 not the same?

Example: x = 10, n = 10
(x % n) -1 = (10 % 10) - 1 = -1
x % (n+1) = 10 % (11) = 10