Program to find count of numbers having odd number of divisors in given range | Function to count numbers having odd number of divisors in range [ A , B ] ; Variable to odd divisor count ; Iterate from a to b and count their number of divisors ; Variable to divisor count ; If count of divisor is odd then increase res by 1 ; Driver code
function OddDivCount ( a , b ) { let res = 0 ; for ( let i = a ; i <= b ; ++ i ) { let divCount = 0 ; for ( let j = 1 ; j <= i ; ++ j ) { if ( i % j == 0 ) { ++ divCount ; } } if ( ( divCount % 2 ) != 0 ) { ++ res ; } } return res ; } let a = 1 , b = 10 ; document . write ( OddDivCount ( a , b ) ) ;