Unprimeable Numbers | function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; function to check if n is a unprimeable Number ; number should be composite ; converting N to string ; loop to change digit at every character one by one . ; loop to store every digit one by one at index j ; Driver code ; Function Call
def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 5 , int ( n ** 0.5 ) + 1 , 6 ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def isUnPrimeableNum ( N ) : NEW_LINE INDENT if ( isPrime ( N ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT s = str ( N ) NEW_LINE for j in range ( len ( s ) ) : NEW_LINE INDENT str1 = s NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT c = str ( i ) NEW_LINE str1 = str1 [ : j ] + c + str1 [ j + 1 : ] NEW_LINE Num = int ( str1 ) NEW_LINE if ( str1 [ j ] != s [ j ] and isPrime ( Num ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT n = 200 NEW_LINE if ( isUnPrimeableNum ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT