Why this recursion fails but while loop with the same implementation passed

As a request , please tell

problem code : MISINTER
problem link : Misinterpretation Practice Coding Problem - CodeChef

my failed submission using recursion : CodeChef: Practical coding for everyone

my correct submission using while loop with same implementation that recursion does : CodeChef: Practical coding for everyone

when I give large input to recursion implementation it gives runtime error and also responding bad_alloc . what mistake I done in this recursive implementation

As a request please tell, why