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 program to test above function
def countOddPrimeFactors ( n ) : NEW_LINE INDENT result = 1 ; NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n /= 2 NEW_LINE DEDENT i = 3 NEW_LINE while i * i <= n : NEW_LINE INDENT divCount = 0 NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT n /= i NEW_LINE divCount = divCount + 1 NEW_LINE DEDENT result = result * divCount + 1 NEW_LINE i = i + 2 NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT result = result * 2 NEW_LINE DEDENT return result NEW_LINE DEDENT def politness ( n ) : NEW_LINE INDENT return countOddPrimeFactors ( n ) - 1 ; NEW_LINE DEDENT n = 90 NEW_LINE print " Politness ▁ of ▁ " , n , " ▁ = ▁ " , politness ( n ) NEW_LINE n = 15 NEW_LINE print " Politness ▁ of ▁ " , n , " ▁ = ▁ " , politness ( n ) NEW_LINE