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 for loop 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
function checkSemiprime ( num ) { let cnt = 0 ; for ( let i = 2 ; cnt < 2 && i * i <= num ; ++ i ) { while ( num % i == 0 ) { num = parseInt ( num / i , 10 ) ; ++ cnt ; } } if ( num > 1 ) ++ cnt ; return cnt == 2 ; } function isEmirpimes ( n ) { if ( checkSemiprime ( n ) == false ) return false ; let r = 0 ; for ( let t = n ; t != 0 ; t = parseInt ( t / n , 10 ) ) r = r * 10 + t % 10 ; if ( r == n ) return false ; return ( checkSemiprime ( r ) ) ; } let n = 15 ; if ( isEmirpimes ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;