Recursive sequence(some test cases failing) - SPOJ

https://cb.lk/undefined
sir this is my code, i tried to implement it same as what you have done it in that PDF but don’t know why it’s showing wrong answer on SPOJ and on hacker block test case 4 and test case 6 are failing, please help me out with it. I’ve spent like one whole day on the same but still can’t figure out those edge cases.
Hope you’ll check it out soon…

save the code in ide and save and paste the link

https://ide.codingblocks.com/#/s/31589
this is it sir