Pierpont Prime | Python3 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
def printPierpont ( n ) : NEW_LINE INDENT arr = [ False ] * ( n + 1 ) ; NEW_LINE two = 1 ; NEW_LINE three = 1 ; NEW_LINE while ( two + 1 < n ) : NEW_LINE INDENT arr [ two ] = True ; NEW_LINE while ( two * three + 1 < n ) : NEW_LINE INDENT arr [ three ] = True ; NEW_LINE arr [ two * three ] = True ; NEW_LINE three *= 3 ; NEW_LINE DEDENT three = 1 ; NEW_LINE two *= 2 ; NEW_LINE DEDENT v = [ ] ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] ) : NEW_LINE INDENT v . append ( i + 1 ) ; NEW_LINE DEDENT DEDENT arr1 = [ False ] * ( len ( arr ) ) ; NEW_LINE p = 2 ; NEW_LINE while ( p * p < n ) : NEW_LINE INDENT if ( arr1 [ p ] == False ) : NEW_LINE INDENT for i in range ( p * 2 , n , p ) : NEW_LINE INDENT arr1 [ i ] = True ; NEW_LINE DEDENT DEDENT p += 1 ; NEW_LINE DEDENT for i in range ( len ( v ) ) : NEW_LINE INDENT if ( not arr1 [ v [ i ] ] ) : NEW_LINE INDENT print ( v [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT n = 200 ; NEW_LINE printPierpont ( n ) ; NEW_LINE