Right | Generate all prime numbers less than n . ; Initialize all entries of boolean array as true . A value in isPrime [ i ] will finally be false if i is Not a prime , else true bool isPrime [ n + 1 ] ; ; If isPrime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Returns true if n is right - truncatable , else false ; Generating primes using Sieve ; Checking whether the number remains prime when the last ( " right " ) digit is successively removed ; Driver Code
< ? php function sieveOfEratosthenes ( $ n , & $ isPrime ) { $ isPrime [ 0 ] = $ isPrime [ 1 ] = false ; for ( $ p = 2 ; $ p * $ p <= $ n ; $ p ++ ) { if ( $ isPrime [ $ p ] == true ) { for ( $ i = $ p * 2 ; $ i <= $ n ; $ i += $ p ) $ isPrime [ $ i ] = false ; } } } function rightTruPrime ( $ n ) { $ isPrime = array_fill ( 0 , $ n + 1 , true ) ; sieveOfEratosthenes ( $ n , $ isPrime ) ; while ( $ n ) { if ( $ isPrime [ $ n ] ) $ n = ( int ) ( $ n / 10 ) ; else return false ; } return true ; } $ n = 59399 ; if ( rightTruPrime ( $ n ) ) echo " Yes STRNEWLINE " ; else echo " No STRNEWLINE " ; ? >