Smallest Special Prime which is greater than or equal to a given number | Function to check whether the number is a special prime or not ; While number is not equal to zero ; If the number is not prime return false . ; Else remove the last digit by dividing the number by 10. ; If the number has become zero then the number is special prime , hence return true ; Function to find the Smallest Special Prime which is greater than or equal to a given number ; Initially all numbers are considered Primes . ; There is always an answer possible ; Checking if the number is a special prime or not ; If yes prvar the number and break the loop . ; Else increment the number . ; Driver code
function checkSpecialPrime ( sieve , num ) { while ( num > 0 ) { if ( sieve [ num ] ) { return false ; } num = parseInt ( num / 10 ) ; } return true ; } function findSpecialPrime ( N ) { var sieve = Array . from ( { length : N * 10 + 1 } , ( _ , i ) => false ) ; sieve [ 0 ] = true ; sieve [ 1 ] = true ; var i = 0 , j = 0 ; for ( i = 2 ; i <= N * 10 ; i ++ ) { if ( ! sieve [ i ] ) { for ( j = i * i ; j <= N * 10 ; j += i ) { sieve [ j ] = true ; } } } while ( true ) { if ( checkSpecialPrime ( sieve , N ) ) { document . write ( N + " " ) ; break ; } else N ++ ; } } var N = 379 ; findSpecialPrime ( N ) ; N = 100 ; findSpecialPrime ( N ) ;