Count all perfect divisors of a number | Utility function to check perfect square number ; Returns count all perfect divisors of n ; Initialize result ; Consider every number that can be a divisor of n ; If i is a divisor ; Driver Code
function isPerfectSquare ( n ) { let sq = Math . sqrt ( n ) ; return ( n == sq * sq ) ; } function countPerfectDivisors ( n ) { let count = 0 ; for ( let i = 1 ; i * i <= n ; ++ i ) { if ( n % i == 0 ) { if ( isPerfectSquare ( i ) ) ++ count ; if ( n / i != i && isPerfectSquare ( n / i ) ) ++ count ; } } return count ; } let n = 16 ; document . write ( " " + " " + n ) ; document . write ( " " + countPerfectDivisors ( n ) + " " ) ; n = 12 ; document . write ( " " + " " + n ) ; document . write ( " " + countPerfectDivisors ( n ) ) ;