Tetradic Primes | Function to check if the number N having all digits lies in the set ( 0 , 1 , 8 ) ; Function to check if the number N is palindrome ; Function to check if a number N is Tetradic ; Function to generate all primes and checking whether number is Tetradic or not ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Print all Tetradic prime numbers ; Checking whether the given number is prime Tetradic or not ; Driver code
function isContaindigit ( n ) { while ( n > 0 ) { if ( ! ( n % 10 == 0 n % 10 == 1 n % 10 == 8 ) ) return false ; n = parseInt ( n / 10 , 10 ) ; } return true ; } function ispalindrome ( n ) { let temp = n . toString ( ) ; let l = temp . length ; for ( let i = 0 ; i < parseInt ( l / 2 , 10 ) ; i ++ ) { if ( temp [ i ] != temp [ l - i - 1 ] ) return false ; } return true ; } function isTetradic ( n ) { if ( ispalindrome ( n ) && isContaindigit ( n ) ) return true ; return false ; } function printTetradicPrimesLessThanN ( n ) { let prime = new Array ( n + 1 ) ; prime . fill ( true ) ; let p = 2 ; while ( p * p <= n ) { if ( prime [ p ] ) { for ( let i = p * 2 ; i < n + 1 ; i += p ) prime [ i ] = false ; } p += 1 ; } for ( p = 2 ; p < n + 1 ; p ++ ) { if ( prime [ p ] && isTetradic ( p ) ) document . write ( p + " " ) ; } } let n = 1000 ; printTetradicPrimesLessThanN ( n ) ;