Help with the code for Puppy and GCD.

My code is giving WA for Puppy and GCD.
Code= CodeChef: Practical coding for everyone

Help me and tell where i am wrong.

The way i solved it is find out the max value you get when you find N%i, where 2<=i<=K, and print that max value.

You can refer to the editorial of the problem here: PUPPYGCD - Editorial - editorial - CodeChef Discuss