Chef and beautiful number march challenge

CodeChef: Practical coding for everyone this is my solution. It is working for mine every input. I don’t know why it gives WA. please help.