Pierpont Prime | Javascript program to print Pierpont prime numbers smaller than n . ; Finding all numbers having factor power of 2 and 3 Using sieve ; Storing number of the form 2 ^ i . 3 ^ k + 1. ; Finding prime number using sieve of Eratosthenes . Reusing same array as result of above computations in v . ; Printing n pierpont primes smaller than n ; Driven Program
function printPierpont ( n ) { var arr = Array ( n + 1 ) . fill ( false ) ; var two = 1 , three = 1 ; while ( two + 1 < n ) { arr [ two ] = true ; while ( two * three + 1 < n ) { arr [ three ] = true ; arr [ two * three ] = true ; three *= 3 ; } three = 1 ; two *= 2 ; } var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] ) v . push ( i + 1 ) ; arr = Array ( n + 1 ) . fill ( false ) ; for ( var p = 2 ; p * p < n ; p ++ ) { if ( arr [ p ] == false ) for ( var i = p * 2 ; i < n ; i += p ) arr [ i ] = true ; } for ( var i = 0 ; i < v . length ; i ++ ) if ( ! arr [ v [ i ] ] ) document . write ( v [ i ] + " " ) ; } var n = 200 ; printPierpont ( n ) ;