


1. Ninja can use the same Fibonacci number any number of times.
2. It is also guaranteed that there are always some Fibonacci numbers whose sum is equal to ‘SUM’.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single integer ‘SUM’ denotes the sum of some Fibonacci numbers.
For each test case, print the minimum number of Fibonacci numbers whose sum is equal to ‘SUM’.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 50
1 <= ‘SUM’ <= 10000
Time limit: 1 sec
The basic idea is we first subtract the biggest Fibonacci number ‘X’ from ‘SUM’. Then recursively find the answer for ‘SUM’ - ‘X’.
Recurrence relation is : f(‘SUM’) = f(‘SUM’ - ‘X’) + 1.
First, we find all the Fibonacci numbers till ‘SUM’. Then we keep subtracting the maximum Fibonacci numbers less than or equal to ‘SUM’ and update the count.
We are only converting the above recursive approach into an iterative approach.