Program to find count of numbers having odd number of divisors in given range | Function to return the count of divisors of a number ; Count the powers of the current prime i which divides a ; Update the count of divisors ; Reset the count ; If the remaining a is prime then a ^ 1 will be one of its prime factors ; Function to count numbers having odd number of divisors in range [ A , B ] ; To store the count of elements having odd number of divisors ; Iterate from a to b and find the count of their divisors ; To store the count of divisors of i ; If the divisor count of i is odd ; Driver code
def divisor ( a ) : NEW_LINE INDENT div = 1 ; NEW_LINE count = 0 ; NEW_LINE for i in range ( 2 , int ( pow ( a , 1 / 2 ) ) + 1 ) : NEW_LINE INDENT while ( a % i == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE a = a / i ; NEW_LINE DEDENT div = div * ( count + 1 ) ; NEW_LINE count = 0 ; NEW_LINE DEDENT if ( a > 1 ) : NEW_LINE INDENT div = div * ( 2 ) ; NEW_LINE DEDENT return div ; NEW_LINE DEDENT def OddDivCount ( a , b ) : NEW_LINE INDENT res = 0 ; NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT divCount = divisor ( i ) ; NEW_LINE if ( divCount % 2 ) : NEW_LINE INDENT res += 1 ; NEW_LINE DEDENT DEDENT return res ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a , b = 1 , 10 ; NEW_LINE print ( OddDivCount ( a , b ) ) ; NEW_LINE DEDENT