Pierpont Prime | PHP 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 ; Driver Code
< ? php function printPierpont ( $ n ) { $ arr = array_fill ( 0 , $ n + 1 , false ) ; $ 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 ; } $ v ; $ x = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ arr [ $ i ] ) $ v [ $ x ++ ] = $ i + 1 ; $ arr1 = array_fill ( 0 , count ( $ arr ) , false ) ; for ( $ p = 2 ; $ p * $ p < $ n ; $ p ++ ) { if ( $ arr1 [ $ p ] == false ) for ( $ i = $ p * 2 ; $ i < $ n ; $ i += $ p ) $ arr1 [ $ i ] = true ; } for ( $ i = 0 ; $ i < $ x ; $ i ++ ) if ( ! $ arr1 [ $ v [ $ i ] ] ) echo $ v [ $ i ] . " ▁ " ; } $ n = 200 ; printPierpont ( $ n ) ; ? >