%I #37 May 30 2026 16:40:42
%S 4,5,7,1,4,1,5,1,1,2,1,1,9,1,1,1,2,1,1,2,1,1,1,1,1,6,1,8,1,1,1,1,2,1,
%T 2,1,1,1,1,1,2,1,3,1,2,1,1,1,4,1,1,2,1,1,1,1,2,1,1,2,1,1,1,3,1,1,1,1,
%U 3,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,1,1
%N a(n) = index j of the first composite number in the sequence prime(1)*...*prime(n-1)*prime(n+1)*...*prime(j) + prime(n).
%C This is based on a modification of Euclid's proof of the infinitude of primes.
%H Robert Israel, <a href="/A237196/b237196.txt">Table of n, a(n) for n = 1..10000</a>
%H Alexander Bogomolny, <a href="http://www.cut-the-knot.org/proofs/InfinitudeOfProofs.shtml">Infinitely many proofs that there are infinitely many primes</a>
%H Alexander Bogomolny, <a href="/A237196/a237196.txt">Python program</a>
%H Des MacHale, <a href="https://doi.org/10.2307/3621650">Infinitely many proofs that there are infinitely many primes</a>, Math. Gazette, 97 (No. 540, 2013), 495-498.
%e This is a modification of Euclid's proof of the infinitude of primes. Instead of 1, add a prime but exclude it from the product. For example, primes: 3+2, 3*5+2, 3*5*7+2, but 3*5*7*11+2 is composite. This is the 4 at the beginning of the sequence.
%p P:= select(isprime,[2,seq(i,i=3..10^5,2)]):
%p f:= proc(n) local j,p,t;
%p t:= 1:
%p for j from 1 do
%p if j <> n then t:= t*P[j] fi;
%p if not isprime(t+P[n]) then if j >= n then return j-1 else return j fi fi;
%p od
%p end proc:
%p map(f, [$1..100]); # _Robert Israel_, May 08 2024
%o (Python) see Python program link
%o (PARI) iscomposite(n) = (n != 1) && !isprime(n);
%o val(j, n) = my(p = prod(k=1, j, prime(k))); if (n<=j, p = p/prime(n)); p + prime(n);
%o a(n) = my(j = 1, prev = 0, nb = 1, newv); while (!iscomposite(newv = val(j, n)), if (newv != prev, nb++); j++; prev = newv;); if (n==1, nb-1, nb); \\ _Michel Marcus_, Apr 15 2014; corrected May 09 2024
%K nonn
%O 1,1
%A _Alexander Bogomolny_, Feb 04 2014
%E New name, data corrected and extended by _Michel Marcus_, Apr 15 2014