# Find the first 20 primes found by the classical proof of the infinitude of the set of primes

Begin with P={2}; then form,m, the sum of 1 with the product overall elements of P. Place the smallest prime factor of m into P and repeat.

Suppose p = {p1,p2,...,pr}, then m = 1+ p1p2p3...pr.

Example:

2 is prime and 2+1 = 3 is prime;

2 * 3 +1 = 7 is prime;

2 * 3 * 7 +1 = 43 is prime;

2 * 3 * 7 * 43 +1 = 1807 = 13 * 139, then 13 is the prime;

Thus the first 5 prime number found by the classical proof is {2,3,7,43,13}.

So how to use this proof to find the first 20 prime in Mathematica? Thank you.

Clear["Global*"]

n = 20;

(p = Nest[Join[#, {FactorInteger[1 + Times @@ #][[1, 1]]}] &,
{2}, n - 1]) // AbsoluteTiming

(* {57.663, {2, 3, 7, 43, 13, 53, 5, 6221671, 38709183810571, 139, 2801,
11, 17, 5471, 52662739, 23003, 30693651606209, 37, 1741, 1313797957}} *)

Length[p]

(* 20 *)

And @@ (PrimeQ /@ p)

(* True *)
`
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}