Check if a number exists with X divisors out of which Y are composite | Python3 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
import math NEW_LINE def factorize ( N ) : NEW_LINE INDENT count = 0 NEW_LINE cnt = 0 NEW_LINE while ( ( N % 2 ) == 0 ) : NEW_LINE INDENT N = N // 2 NEW_LINE count += 1 NEW_LINE DEDENT cnt = cnt + count NEW_LINE sq = int ( math . sqrt ( N ) ) NEW_LINE for i in range ( 3 , sq , 2 ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N % i == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE N = N // i NEW_LINE DEDENT cnt = cnt + count NEW_LINE DEDENT if ( N > 2 ) : NEW_LINE INDENT cnt = cnt + 1 NEW_LINE DEDENT return cnt NEW_LINE DEDENT def ifNumberExists ( X , Y ) : NEW_LINE INDENT C = X - Y - 1 NEW_LINE dsum = factorize ( X ) NEW_LINE if ( dsum >= C ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = 6 NEW_LINE Y = 4 NEW_LINE ifNumberExists ( X , Y ) NEW_LINE DEDENT