Count all perfect divisors of a number | 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
< ? php function isPerfectSquare ( $ n ) { $ sq = sqrt ( $ n ) ; return ( $ n == $ sq * $ sq ) ; } function countPerfectDivisors ( $ n ) { $ count = 0 ; for ( $ i = 1 ; $ i * $ i <= $ n ; ++ $ i ) { if ( $ n % $ i == 0 ) { if ( isPerfectSquare ( $ i ) ) ++ $ count ; if ( $ n / $ i != $ i && isPerfectSquare ( $ n / $ i ) ) ++ $ count ; } } return $ count ; } $ n = 16 ; echo " Total ▁ perfect ▁ divisors ▁ of ▁ " , $ n , " ▁ = ▁ " , countPerfectDivisors ( $ n ) , " STRNEWLINE " ; $ n = 12 ; echo " Total ▁ perfect ▁ divisors ▁ of ▁ " , $ n , " ▁ = ▁ " , countPerfectDivisors ( $ n ) ; ? >