Program to find count of numbers having odd number of divisors in given range | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int OddDivCount ( int a , int b ) { int res = 0 ; for ( int i = a ; i <= b ; ++ i ) { int divCount = 0 ; for ( int j = 1 ; j <= i ; ++ j ) { if ( i % j == 0 ) { ++ divCount ; } } if ( divCount % 2 ) { ++ res ; } } return res ; } int main ( ) { int a = 1 , b = 10 ; cout << OddDivCount ( a , b ) << endl ; return 0 ; }