Zeckendorf 's Theorem (Non | Returns the greatest Fibonacci Number smaller than or equal to n . ; Corner cases ; Finds the greatest Fibonacci Number smaller than n . ; Prints Fibonacci Representation of n using greedy algorithm ; Find the greates Fibonacci Number smaller than or equal to n ; Print the found fibonacci number ; Reduce n ; Driver code test above functions
def nearestSmallerEqFib ( n ) : NEW_LINE INDENT if ( n == 0 or n == 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT f1 , f2 , f3 = 0 , 1 , 1 NEW_LINE while ( f3 <= n ) : NEW_LINE INDENT f1 = f2 ; NEW_LINE f2 = f3 ; NEW_LINE f3 = f1 + f2 ; NEW_LINE DEDENT return f2 ; NEW_LINE DEDENT def printFibRepresntation ( n ) : NEW_LINE INDENT while ( n > 0 ) : NEW_LINE INDENT f = nearestSmallerEqFib ( n ) ; NEW_LINE print f , NEW_LINE n = n - f NEW_LINE DEDENT DEDENT n = 30 NEW_LINE print " Non - neighbouring ▁ Fibonacci ▁ Representation ▁ of " , n , " is " NEW_LINE printFibRepresntation ( n ) NEW_LINE