The sequence of primorial primes is given as the increasing values of n where primorial(n) ± 1 is prime.

Noting that the n'th primorial is defined as the multiplication of the smallest n primes, the sequence is of the number of primes, in order that when multiplied together is one-off being a prime number itself.



Task

Generate and show here the first ten values of the sequence.



Optional extended task

Show the first twenty members of the series.



Notes
 
 This task asks for the primorial indices that create the final primorial prime numbers, so there should be no ten-or-more digit numbers in the program output (although extended precision integers will be needed for intermediate results).
 There is some confusion in the references, but for the purposes of this task the sequence begins with n = 1.
 Probabilistic primality tests are allowed, as long as they are good enough such that the output shown is correct.


Related tasks

 Primorial numbers
 Factorial


See also

 Primorial prime Wikipedia.
 Primorial prime from The Prime Glossary.
 Sequence A088411 from The On-Line Encyclopedia of Integer Sequences


' version 23-10-2016
' compile with: fbc -s console
 
#Define max 9999    ' max number for the sieve
 
#Include Once "gmp.bi"
 
Dim As mpz_ptr p, p1
p  = Allocate(Len(__mpz_struct)) : Mpz_init_set_ui(p, 1)
p1 = Allocate(Len(__mpz_struct)) : Mpz_init(p1)
 
Dim As UInteger i, n, x
Dim As Byte prime(max)
 
' Sieve of Eratosthenes
For i = 4 To max Step 2
  prime(i) = 1
Next
For i = 3 To Sqr(max) Step 2
  If prime(i) = 1 Then Continue For
  For n = i * i To max Step i * 2
    prime(n) = 1
  Next
Next
 
n = 0 : x = 0
For i = 2 To max
  If prime(i) = 1 Then Continue For
  x = x + 1
  mpz_mul_ui(p, p, i)
  mpz_sub_ui(p1, p, 1)
  If mpz_probab_prime_p(p1, 25) > 0 Then
    Print Using "####"; x; : Print ",";
    n += 1
    If n >= 20 Then Exit For
    Continue For
  End If
  mpz_add_ui(p1, p, 1)
  If mpz_probab_prime_p(p1, 25) > 0 Then
    Print Using "####"; x; : Print ",";
    n += 1
    If n >= 20 Then Exit For
  End If
Next
 
Print
mpz_clear(p)
mpz_clear(p1)
 
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End