Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #36 May 09 2024 09:09:30
%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="http://dx.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