Please help me find error in code or optimization in code. I am gettin TLE on SPOJ

I am getting TLE on SPOJ. I tried different optimization but couldn’t get accepted. Can you please help me understand what is the issue?

It is a standard question based on Zeckendorf’s theorem.

Question link:- https://www.spoj.com/problems/FIBOREP/
Ide link:- https://ide.codingblocks.com/s/224246

Thanks in advance.