Mathematica Asked by User796 on December 16, 2020
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 *)
Correct answer by Bob Hanlon on December 16, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP