Definition
A Fortunate number is the smallest integer m > 1 such that for a given positive integer n, primorial(n) + m is a prime number, where primorial(n) is the product of the first n prime numbers.

For example the first fortunate number is 3 because primorial(1) is 2 and 2 + 3 = 5 which is prime whereas 2 + 2 = 4 is composite.



Task
After sorting and removal of any duplicates, compute and show on this page the first 8 Fortunate numbers or, if your language supports big integers, the first 50 Fortunate numbers.



Related task
 Primorial numbers


See also
 oeis:A005235 Fortunate numbers 
 oeis:A046066 Fortunate numbers, sorted with duplicates removed


import algorithm, sequtils, strutils
import bignum
 
const
  N = 50      # Number of fortunate numbers.
  Lim = 75    # Number of primorials to compute.
 
 
iterator primorials(lim: Positive): Int =
  var prime = newInt(2)
  var primorial = newInt(1)
  for _ in 1..lim:
    primorial *= prime
    prime = prime.nextPrime()
    yield primorial
 
 
var list: seq[int]
for p in primorials(Lim):
  var m = 3
  while true:
    if probablyPrime(p + m, 25) != 0:
      list.add m
      break
    inc m, 2
 
list.sort()
list = list.deduplicate(true)
if list.len < N:
  quit "Not enough values. Wanted $1, got $2.".format(N, list.len), QuitFailure
list.setLen(N)
echo "First $# fortunate numbers:".format(N)
for i, m in list:
  stdout.write ($m).align(3), if (i + 1) mod 10 == 0: '\n' else: ' '