Time limit exceeded in bigger integer number


#1

I was solving this question with the help of recursion but how can i apply the memoriazation/ Dynamic programming in this question. Can you please help me out!!