I want to solve the question involving number , how should i solve such question

https://www.codechef.com/viewsolution/81574183
i have this problem i want to know how should i train myself so that i can solve problem like this in near future,