Codechef K Fibonacci

maths

I am getting WA for 2 subtasks in this question : https://www.codechef.com/problems/KFIB 

My solution : https://www.codechef.com/viewsolution/18321444

Could someone please point out my mistake ?

shivhek25
Shivam Singhal
shivhek25

Please Log in to answer

Note: Your answer should not be too short. Please wait a few seconds for the editor to load



Please make sure the answer is not too short

1 Answer

preda2or
preda2or 23:33, Apr 20
Shubham Kumar Gupta

The formula you are using to find the next term (i.e 2*a[i-1] -1) isn't correct .

Try this test case:

6 2

Your output: 9

Correct output: 8

Hope it helps :)




Please make sure the answer is not too short
2 Upvotes
Comments
shivhek25 (Shivam Singhal) 16:05, Apr 22

Yes, it helped. The formula wasn't totally wrong. I had to add another case. Thank you.