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


use strict;
use warnings;
use List::Util <first uniq>;
use ntheory qw<pn_primorial is_prime>;
 
my $upto = 50;
my @candidates;
for my $p ( map { pn_primorial($_) } 1..2*$upto ) {
    push @candidates, first { is_prime($_ + $p) } 2..100*$upto;
}
 
my @fortunate = sort { $a <=> $b } uniq grep { is_prime $_ } @candidates;
 
print "First $upto distinct fortunate numbers:\n" .
    (sprintf "@{['%6d' x $upto]}", @fortunate) =~ s/(.{60})/$1\n/gr;