Given a number, find a representation of number as sum of non-consecutive Fibonacci numbers.
Input: n = 10 Output: 8 2 8 and 2 are two non-consecutive Fibonacci Numbers and sum of them is 10. Input: n = 30 Output: 21 8 1 21, 8 and 1 are non-consecutive Fibonacci Numbers and sum of them is 30.
The idea is to use Greedy Algorithm.
1) Let n be input number 2) While n >= 0 a) Find the greatest Fibonacci Number smaller than n. Let this number be 'f'. Print 'f' b) n = n - f
Non-neighbouring Fibonacci Representation of 30 is 21 8 1
Please refer complete article on Zeckendorf’s Theorem (Non-Neighbouring Fibonacci Representation) for more details!
- Python Program to print digit pattern
- Python | Extract key-value of dictionary in variables
- Python program to convert time from 12 hour to 24 hour format
- Google Chrome Dino Bot using Image Recognition | Python
- Python | Use of __slots__
- Python - Summation of float string list
- Python | Animated Banner showing 'GeeksForGeeks'
- Python | Segregate list elements by Suffix
- Python Program for Selection Sort
- Python Program for Bubble Sort
- Python Program for Insertion Sort
- Python Program for Heap Sort
- Python Program for Counting Sort
- Python Program for Radix Sort
- Python Program for n-th Fibonacci number