Check whether a number is Emirpimes or not | Checking whether a number is semi - prime or not ; Increment count of prime numbers ; If number is still greater than 1 , after exiting the add it to the count variable as it indicates the number is a prime number ; Return '1' if count is equal to '2' else return '0 ; Checking whether a number is emirpimes or not ; Number itself is not semiprime . ; Finding reverse of n . ; The definition of emirpimes excludes palindromes , hence we do not check further , if the number entered is a palindrome ; Checking whether the reverse of the semi prime number entered is also a semi prime number or not ; Driver Code
def checkSemiprime ( num ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE i = 2 ; NEW_LINE while ( cnt < 2 and ( i * i ) <= num ) : NEW_LINE INDENT while ( num % i == 0 ) : NEW_LINE INDENT num /= i ; NEW_LINE cnt += 1 ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT if ( num > 1 ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT return cnt == 2 ; NEW_LINE DEDENT def isEmirpimes ( n ) : NEW_LINE INDENT if ( checkSemiprime ( n ) == False ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT r = 0 ; NEW_LINE t = n ; NEW_LINE while ( t != 0 ) : NEW_LINE INDENT r = r * 10 + t % 10 ; NEW_LINE t = t / n ; NEW_LINE DEDENT if ( r == n ) : NEW_LINE INDENT return false ; NEW_LINE DEDENT return ( checkSemiprime ( r ) ) ; NEW_LINE DEDENT n = 15 ; NEW_LINE if ( isEmirpimes ( n ) ) : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT