Enlightened Numbers | Python3 implementation of the above approach ; Function to check if N is a Composite Number ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to return concatenation of distinct prime factors of a given number n ; Handle prime factor 2 explicitly so that can optimally handle other prime factors . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Function to check if a number is is an enlightened number ; Number should not be prime ; Converting N to string ; Function call ; Driver code
import math NEW_LINE def isComposite ( n ) : NEW_LINE INDENT if n <= 3 : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i = 5 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT i = i + 6 NEW_LINE DEDENT return False NEW_LINE DEDENT def concatenatePrimeFactors ( n ) : NEW_LINE INDENT concatenate = " " NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT concatenate += "2" NEW_LINE while ( n % 2 == 0 ) : NEW_LINE INDENT n = int ( n / 2 ) NEW_LINE DEDENT DEDENT i = 3 NEW_LINE while ( i <= int ( math . sqrt ( n ) ) ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT concatenate += str ( i ) NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT n = int ( n / i ) NEW_LINE DEDENT DEDENT i = i + 2 NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT concatenate += str ( n ) NEW_LINE DEDENT return concatenate NEW_LINE DEDENT def isEnlightened ( N ) : NEW_LINE INDENT if ( not isComposite ( N ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT num = str ( N ) NEW_LINE prefixConc = concatenatePrimeFactors ( N ) NEW_LINE return int ( prefixConc ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 250 NEW_LINE if ( isEnlightened ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT