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: function countOddPrimeFactors ( n ) { let result = 1 ; while ( n % 2 == 0 ) n /= 2 ; for ( let i = 3 ; i * i <= n ; i += 2 ) { let 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 ; } let n = 90 ; document . write ( " " + n + " " + politness ( n ) + " " ) ; n = 15 ; document . write ( " " + n + " " + politness ( n ) ) ;