Wrong answer in FLOW005

I am having Wrong Answer regularly, please tell me why it is so, I have checked each and every case.

Question statement: https://www.codechef.com/problems/FLOW005

My solution: Solution

You Are Changing The rem value but left out the n value unchanged. Inplace of rem=n%value use n=n%value.