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
def factors ( n , k ) : NEW_LINE INDENT v = [ ] ; NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT v . append ( 2 ) ; NEW_LINE n //= 2 ; NEW_LINE DEDENT if ( len ( v ) >= k ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT for i in range ( 3 , int ( n ** ( 1 / 2 ) ) , 2 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT n = n // i ; NEW_LINE v . append ( i ) ; NEW_LINE DEDENT if ( len ( v ) >= k ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT v . append ( n ) ; NEW_LINE DEDENT if ( len ( v ) >= k ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT def operation ( n , k ) : NEW_LINE INDENT answered = False ; NEW_LINE if ( n < k ) : NEW_LINE INDENT answered = True ; NEW_LINE print ( " No " ) ; NEW_LINE DEDENT ok = factors ( n , k ) ; NEW_LINE if ( not ok and not answered ) : NEW_LINE INDENT answered = True ; NEW_LINE print ( " No " ) ; NEW_LINE DEDENT if ( ok and not answered ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 ; NEW_LINE k = 2 ; NEW_LINE operation ( n , k ) ; NEW_LINE DEDENT