https://www.spoj.com/problems/NUMGAME/

I am getting tle how to get ac ans.
My approach was given in the code->
https://ide.codingblocks.com/s/55800