Count of Fibonacci divisors of a given number | Function to create hash table to check Fibonacci numbers ; Function to count number of divisors of N which are fibonacci numbers ; If divisors are equal , check and count only one ; Otherwise check and count both ; 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 countFibonacciDivisors ( n ) { let hash = new Set ( ) ; createHash ( hash , n ) ; let cnt = 0 ; for ( let i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( ( n / i == i ) && ( hash . has ( n / i ) ) ) cnt ++ ; else { if ( hash . has ( n / i ) ) cnt ++ ; if ( hash . has ( n / ( n / i ) ) ) cnt ++ ; } } } return cnt ; } let n = 12 ; document . write ( countFibonacciDivisors ( n ) ) ;