Count of Fibonacci divisors of a given number | C # program to count number of divisors of N which are Fibonacci numbers ; 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
using System ; using System . Collections . Generic ; class GFG { static void createHash ( HashSet < int > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . Add ( prev ) ; hash . Add ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . Add ( temp ) ; prev = curr ; curr = temp ; } } static int countFibonacciDivisors ( int n ) { HashSet < int > hash = new HashSet < int > ( ) ; createHash ( hash , n ) ; int cnt = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( ( n / i == i ) && ( hash . Contains ( n / i ) ) ) cnt ++ ; else { if ( hash . Contains ( n / i ) ) cnt ++ ; if ( hash . Contains ( n / ( n / i ) ) ) cnt ++ ; } } } return cnt ; } public static void Main ( String [ ] args ) { int n = 12 ; Console . Write ( countFibonacciDivisors ( n ) ) ; } }