Find two Fibonacci numbers whose sum can be represented as N | Function to create hash table to check Fibonacci numbers ; Storing the first two numbers in the hash ; Finding Fibonacci numbers up to N and storing them in the hash ; Function to find the Fibonacci pair with the given sum ; creating a set containing all fibonacci numbers ; Traversing all numbers to find first pair ; If both i and ( N - i ) are Fibonacci ; Prleting the pair because i + ( N - i ) = N ; If no fibonacci pair is found whose sum is equal to n ; Driver code
function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr < maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function findFibonacciPair ( n ) { let hash = new Set ( ) ; createHash ( hash , n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( hash . has ( i ) && hash . has ( n - i ) ) { document . write ( i + " " + ( n - i ) + " " ) ; return ; } } document . write ( " " + " " ) ; } let N = 90 ; findFibonacciPair ( N ) ;