Honaker Prime Number | Javascript program for above approach ; Function to precompute the position of every prime number using Sieve ; 0 and 1 are not prime numbers ; Variable to store the position ; Incrementing the position for every prime number ; Function to get sum of digits ; Function to check whether the given number is Honaker Prime number or not ; Precompute the prime numbers till 10 ^ 6 ; Given Number ; Function Call
const limit = 10000000 ; let position = Array ( limit + 1 ) . fill ( 0 ) ; function sieve ( ) { position [ 0 ] = - 1 ; position [ 1 ] = - 1 ; let pos = 0 ; for ( let i = 2 ; i <= limit ; i ++ ) { if ( position [ i ] == 0 ) { position [ i ] = ++ pos ; for ( let j = i * 2 ; j <= limit ; j += i ) position [ j ] = - 1 ; } } } function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = parseInt ( n / 10 ) ; } return sum ; } function isHonakerPrime ( n ) { let pos = position [ n ] ; if ( pos == - 1 ) return false ; return getSum ( n ) == getSum ( pos ) ; } sieve ( ) ; let N = 121 ; if ( isHonakerPrime ( N ) ) document . write ( " " ) ; else document . write ( " " ) ;