Check if a number exists with X divisors out of which Y are composite | javascript program to check if a number exists having exactly X positive divisors out of which Y are composite divisors ; Count the number of times 2 divides N ; Check for all possible numbers that can divide it ; If N at the end is a prime number . ; Function to check if any such number exists ; Driver code
function factorize ( N ) { var count = 0 ; var cnt = 0 ; while ( ( N % 2 ) == 0 ) { N = N / 2 ; count ++ ; } cnt = cnt + count ; for ( i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } cnt = cnt + count ; } if ( N > 2 ) cnt = cnt + 1 ; return cnt ; } function ifNumberExists ( X , Y ) { var C , dsum ; C = X - Y - 1 ; dsum = factorize ( X ) ; if ( dsum >= C ) document . write ( " " ) ; else document . write ( " " ) ; } var X , Y ; X = 6 ; Y = 4 ; ifNumberExists ( X , Y ) ;