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


Module Pierpoint_Primes {
      Form 80
      Set Fast !
      const NPP=50
      dim pier(1 to 2, 1 to NPP), np(1 to 2) = 0
      def long x = 1, j
      while np(1)<=NPP or np(2)<=NPP
          x++
          j = @is_pierpont(x)
          if j>0 Else Continue
          if j mod 2 = 1 then np(1)++ :if np(1) <= NPP then pier(1, np(1)) = x
          if j > 1 then np(2)++ : if np(2) <= NPP then pier(2, np(2)) = x
      end while
 
      print "First ";NPP;" Pierpont primes of the first kind:"
      for j = 1 to NPP
          print pier(2, j),
      next j
      if pos>0 then print
      print "First ";NPP;" Pierpont primes of the second kind:"
      for j = 1 to NPP
          print pier(1, j),
      next j
      if pos>0 then print
      Set Fast
      function is_prime(n as decimal)
          if n < 2 then = false  : exit function
          if n <4 then = true : exit function
          if n mod 2 = 0 then = false : exit function
          local i as long
          for i = 3 to int(sqrt(n))+1 step 2
              if n mod i = 0 then = false  : exit function
          next i
          = true
      end function
 
      function is_23(n as long)
          while n mod 2 = 0
              n = n div 2
          end while
          while n mod 3 = 0
              n = n div 3
          end while
          if n = 1 then = true else = false
      end function
 
      function is_pierpont(n as long)
          if not @is_prime(n) then = 0& : exit function 'not prime
          Local p1 = @is_23(n+1), p2 = @is_23(n-1)
          if p1 and p2 then = 3  : exit function      'pierpont prime of both kinds
          if p1 then = 1 : exit function              'pierpont prime of the 1st kind
          if p2 then = 2 : exit function              'pierpont prime of the 2nd kind
          = 0                         'prime, but not pierpont
      end function
}
Pierpoint_Primes