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


-- demo/rosetta/Pierpont_primes.exw
with javascript_semantics
include mpfr.e
 
function pierpont(integer n)
    sequence p = {{mpz_init(2)},{}},
             s = {mpz_init(1)}
    integer i2 = 1, i3 = 1
    mpz {n2, n3, t} = mpz_inits(3)
    atom t1 = time()+1
    while min(length(p[1]),length(p[2])) < n do
        mpz_mul_si(n2,s[i2],2)
        mpz_mul_si(n3,s[i3],3)
        if mpz_cmp(n2,n3)<0 then
            mpz_set(t,n2)
            i2 += 1
        else
            mpz_set(t,n3)
            i3 += 1
        end if
        if mpz_cmp(t,s[$]) > 0 then
            s = append(s, mpz_init_set(t))
            mpz_add_ui(t,t,1)
            if length(p[1]) < n and mpz_prime(t) then
                p[1] = append(p[1],mpz_init_set(t))
            end if
            mpz_sub_ui(t,t,2)
            if length(p[2]) < n and mpz_prime(t) then
                p[2] = append(p[2],mpz_init_set(t))
            end if
        end if
        if time()>t1 then
            printf(1,"Found: 1st:%d/%d, 2nd:%d/%d\r",
                     {length(p[1]),n,length(p[2]),n})
            t1 = time()+1
        end if
    end while
    return p
end function
 
--constant limit = 2000         -- 2 mins
--constant limit = 1000         -- 8.1s
constant limit = 250            -- 0.1s
atom t0 = time()
sequence p = pierpont(limit)
constant fs = {"first","second"}
 
for i=1 to length(fs) do
    printf(1,"First 50 Pierpont primes of the %s kind:\n",{fs[i]})
    for j=1 to 50 do
        printf(1,"%8s ", {mpz_get_str(p[i][j])})
        if mod(j,10)=0 then printf(1,"\n") end if
    end for
    printf(1,"\n")
end for
 
constant t = {250,1000,2000}
for i=1 to length(t) do
    integer ti = t[i]
    if ti>limit then exit end if
    for j=1 to length(fs) do
        string zs = shorten(mpz_get_str(p[j][ti]))
        printf(1,"%dth Pierpont prime of the %s kind: %s\n",{ti,fs[j],zs})
    end for
    printf(1,"\n")
end for
printf(1,"Took %s\n", elapsed(time()-t0))
