A Pierpont prime is a prime number of the form: 2u3v + 1 for some non-negative integers  u  and  v .



A Pierpont prime of the second kind is a prime number of the form: 2u3v - 1 for some non-negative integers  u  and  v .


The term "Pierpont primes" is generally understood to mean the first definition, but will be called "Pierpont primes of the first kind" on this page to distinguish them.



Task

 Write a routine (function, procedure, whatever) to find Pierpont primes of the first & second kinds.
 Use the routine to find and display here, on this page, the first 50 Pierpont primes of the first kind.
 Use the routine to find and display here, on this page, the first 50 Pierpont primes of the second kind
 If your language supports large integers, find and display here, on this page, the 250th Pierpont prime of the first kind and the 250th Pierpont prime of the second kind.


See also

 Wikipedia - Pierpont primes
 OEIS:A005109 - Class 1 -, or Pierpont primes
 OEIS:A005105 - Class 1 +, or Pierpont primes of the second kind


#define NPP 50
 
Function isPrime(Byval n As Ulongint) As Boolean
    If n < 2 Then Return false
    If n = 2 Then Return true
    If n Mod 2 = 0 Then Return false
    For i As Uinteger = 3 To Int(Sqr(n))+1 Step 2
        If n Mod i = 0 Then Return false
    Next i
    Return true
End Function
 
Function is_23(Byval n As Uinteger) As Boolean
    While n Mod 2 = 0
        n /= 2
    Wend
    While n Mod 3 = 0
        n /= 3
    Wend
    Return Iif(n=1, true, false)
End Function
 
Function isPierpont(n As Uinteger) As Uinteger
    If Not isPrime(n) Then Return 0  'not prime
    Dim As Uinteger p1 = is_23(n+1), p2 = is_23(n-1)
    If p1 And p2 Then Return 3       'pierpont prime of both kinds
    If p1 Then Return 1              'pierpont prime of the 1st kind
    If p2 Then Return 2              'pierpont prime of the 2nd kind
    Return 0                         'prime, but not pierpont
End Function
 
Dim As Uinteger pier(1 To 2, 1 To NPP), np(1 To 2) = {0, 0}
Dim As Uinteger x = 1, j
While np(1) <= NPP Or np(2) <= NPP
    x += 1
    j = isPierpont(x)
    If j > 0 Then
        If j Mod 2 = 1 Then 
            np(1) += 1
            If np(1) <= NPP Then pier(1, np(1)) = x
        End If
        If j > 1 Then
            np(2) += 1
            If np(2) <= NPP Then pier(2, np(2)) = x
        End If
    End If
Wend
 
Print "First 50 Pierpoint primes of the first kind:"
For j = 1 To NPP
    Print Using " ########"; pier(2, j);
    If j Mod 10 = 0 Then Print
Next j
Print !"\nFirst 50 Pierpoint primes of the secod kind:"
For j = 1 To NPP
    Print Using " ########"; pier(1, j);
    If j Mod 10 = 0 Then Print
Next j
 