Count number of integers less than or equal to N which has exactly 9 divisors | Function to count factors in O ( N ) ; iterate and check if factor or not ; Function to count numbers having exactly 9 divisors ; check for all numbers <= N ; check if exactly 9 factors or not ; Driver Code
function numberOfDivisors ( num ) { let c = 0 ; for ( let i = 1 ; i <= num ; i ++ ) { if ( num % i == 0 ) { c += 1 ; } } return c ; } function countNumbers ( n ) { let c = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( numberOfDivisors ( i ) == 9 ) c += 1 ; } return c ; } let n = 1000 ; document . write ( countNumbers ( n ) ) ;