I am trying to solve Aditi and Magic Tricks (ADMAG) question of August Long Challenge 2015 using the following formula :

Here F is the input no. and n gives the index of that Fibonacci number. I have tried many solutions so far but all in vain. My submissions are this, this, this and this. As you can see, all the codes fail in the last task of each subtask. Now, I am wondering whether this question can be solved using this formula and if the answer is yes then how?

My observations:

- Code is probably failing because of floating-point approximations.
- The code is giving correct answer till the 52nd Fibonacci number (), but problems start arising after that.