Check if a number exists having exactly N factors and K prime factors | Function to compute the number of factors of the given number ; Vector to store the prime factors ; While there are no two multiples in the number , divide it by 2 ; If the size is already greater than K , then return true ; Computing the remaining divisors of the number ; If n is divisible by i , then it is a divisor ; If the size is already greater than K , then return true ; If the size is already greater than K , then return true ; If none of the above conditions satisfies , then return false ; Function to check if it is possible to make a number having total N factors and K prime factors ; If total divisors are less than the number of prime divisors , then print No ; Find the number of factors of n ; Driver Code
function factors ( n , k ) { let v = [ ] ; while ( n % 2 == 0 ) { v . push ( 2 ) ; n = parseInt ( n / 2 ) ; } if ( v . length >= k ) return true ; for ( let i = 3 ; i * i <= n ; i += 2 ) { while ( n % i == 0 ) { n = parseInt ( n / i ) ; v . push ( i ) ; } if ( v . length >= k ) return true ; } if ( n > 2 ) v . push ( n ) ; if ( v . length >= k ) return true ; return false ; } function operation ( n , k ) { let answered = false ; if ( n < k ) { answered = true ; document . write ( " " ) ; } let ok = factors ( n , k ) ; if ( ! ok && ! answered ) { answered = true ; document . write ( " " ) ; } if ( ok && ! answered ) document . write ( " " ) ; } let n = 4 ; let k = 2 ; operation ( n , k ) ;