text: Find politeness of a number | A function to count all odd prime factors of a given number n ; Eliminate all even prime factor of number of n ; n must be odd at this point , so iterate for only odd numbers till sqrt ( n ) ; if i divides n , then start counting of Odd divisors ; If n odd prime still remains then count it ; Driver Code
code: < ? php function countOddPrimeFactors ( $ n ) { $ result = 1 ; while ( $ n % 2 == 0 ) $ n /= 2 ; for ( $ i = 3 ; $ i * $ i <= $ n ; $ i += 2 ) { $ divCount = 0 ; while ( $ n % $ i == 0 ) { $ n /= $ i ; ++ $ divCount ; } $ result *= $ divCount + 1 ; } if ( $ n > 2 ) $ result *= 2 ; return $ result ; } function politness ( $ n ) { return countOddPrimeFactors ( $ n ) - 1 ; } $ n = 90 ; echo " Politness ▁ of ▁ " , $ n , " ▁ = ▁ " , politness ( $ n ) , " STRNEWLINE " ; $ n = 15 ; echo " Politness ▁ of ▁ " , $ n , " ▁ = ▁ " , politness ( $ n ) , " STRNEWLINE " ; ? >