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
< ? php function OddDivCount ( $ a , $ b ) { $ res = 0 ; for ( $ i = $ a ; $ i <= $ b ; ++ $ i ) { $ divCount = 0 ; for ( $ j = 1 ; $ j <= $ i ; ++ $ j ) { if ( $ i % $ j == 0 ) { ++ $ divCount ; } } if ( $ divCount % 2 ) { ++ $ res ; } } return $ res ; } $ a = 1 ; $ b = 10 ; echo OddDivCount ( $ a , $ b ) ; ? >