Task: Sequence of primorial primes





Java: import java.math.BigInteger;

public class PrimorialPrimes {

    final static int sieveLimit = 1550_000;
    static boolean[] notPrime = sieve(sieveLimit);

    public static void main(String[] args) {

        int count = 0;
        for (int i = 1; i < 1000_000 && count < 20; i++) {
            BigInteger b = primorial(i);
            if (b.add(BigInteger.ONE).isProbablePrime(1)
                    || b.subtract(BigInteger.ONE).isProbablePrime(1)) {
                System.out.printf("%d ", i);
                count++;
            }
        }
    }

    static BigInteger primorial(int n) {
        if (n == 0)
            return BigInteger.ONE;

        BigInteger result = BigInteger.ONE;
        for (int i = 0; i < sieveLimit && n > 0; i++) {
            if (notPrime[i])
                continue;
            result = result.multiply(BigInteger.valueOf(i));
            n--;
        }
        return result;
    }

    public static boolean[] sieve(int limit) {
        boolean[] composite = new boolean[limit];
        composite[0] = composite[1] = true;

        int max = (int) Math.sqrt(limit);
        for (int n = 2; n <= max; n++) {
            if (!composite[n]) {
                for (int k = n * n; k < limit; k += n) {
                    composite[k] = true;
                }
            }
        }
        return composite;
    }
}






Fortran:       PROGRAM PRIMORIALP	
      USE PRIMEBAG		
      USE BIGNUMBERS		
      TYPE(BIGNUM) B		
      INTEGER MAXF		
      PARAMETER (MAXF = 18000000)	
      INTEGER I			
      INTEGER FU,FD		
      INTEGER NHIT,HIT(666)	
      CHARACTER*4 WOT		
      CHARACTER*66 ALINE	
      REAL T0,T1		
      MSG = 6	
      WRITE (MSG,1) BIGLIMIT,BIGBASE,HUGE(I)	
    1 FORMAT ('Calculates primorial "primes"',/,
     1 "A primorial prime is a value N such that",/,
     2 "    Primorial(N) - 1 is prime, OR",/,
     3 "    Primorial(N) + 1 is prime, or both.",/,
     4 "and Primorial(N) is the product of the first N prime numbers.",/
     5 "Working with up to ",I0," digits in base ",I0,"."/
     6 "The integer limit is ",I0,/)

c      CALL PREPARE PRIMES	
      IF (.NOT.GRASPPRIMEBAG(66)) STOP "Gan't grab my file
      WRITE (MSG,2)
    2 FORMAT ("Primorial#",3X,"Approx.",8X," -1 Factor +1 Factor Hit")

Commence prime mashing.
  100 NHIT = 0		
      B.LAST = 1	
      B.DIGIT(1) = 1	
      CALL CPU_TIME(T0)	
      DO I = 1,30	
        CALL BIGMULTN(B,PRIME(I))	
c        WRITE (MSG,101) I,PRIME(I),I,B.DIGIT(B.LAST:1:-1)	
  101   FORMAT ("Prime(",I0,") = ",I0,", Primorial(",I0,") = ",	
     1   I0,9I<BIGORDER>.<BIGORDER>,/,(10I<BIGORDER>.<BIGORDER>))	
        FU = -1		
        FD = -1		
        CALL BIGADDN(B,+1)	
        FU = BIGFACTOR(B,MAXF)	
        CALL BIGADDN(B,-2)	
        IF (FU.NE.1) FD = BIGFACTOR(B,MAXF)	
        IF (FU.EQ.1 .OR. FD.EQ.1) THEN	
          WOT = "Yes
          NHIT = NHIT + 1			
          HIT(NHIT) = I				
        ELSE IF (FU.GT.1 .AND. FD.GT.1) THEN	
          WOT = "No."				
        ELSE				
          WOT = "?"				
        END IF				
        CALL BIGADDN(B,1)		
        WRITE (ALINE,102) I,BIGVALUE(B),FD,FU,WOT	
  102   FORMAT (I10,1PE18.10,I10,I10,1X,A)	
        IF (FD.EQ.-1) ALINE(37:38) = ""		
        IF (FD.EQ. 0) ALINE(38:38) = "?"	
        IF (FU.EQ. 0) ALINE(48:48) = "?"	
        WRITE (MSG,"(A)") ALINE		
      END DO		
      CALL CPU_TIME(T1)	

Cast forth some pearls.
      WRITE (MSG,201) HIT(1:NHIT)	
  201 FORMAT (/,"Hit list: ",I0,666(",",I0:))	
      WRITE (MSG,*) "CPU time:",T1 - T0	
      END