How to resolve the algorithm Euclid-Mullin sequence step by step in the Fermat programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Euclid-Mullin sequence step by step in the Fermat programming language

Table of Contents

Problem Statement

The Euclid–Mullin sequence is an infinite sequence of distinct prime numbers, in which each element is the least prime factor of one plus the product of all earlier elements. The first element is usually assumed to be 2. So the second element is : (2) + 1 = 3 and the third element is : (2 x 3) + 1 = 7 as this is prime. Although intermingled with smaller elements, the sequence can produce very large elements quite quickly and only the first 51 have been computed at the time of writing. Compute and show here the first 16 elements of the sequence or, if your language does not support arbitrary precision arithmetic, as many as you can. Compute the next 11 elements of the sequence. OEIS sequence A000945

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Euclid-Mullin sequence step by step in the Fermat programming language

Source code in the fermat programming language

Func Firstfac(n) = 
    j := 3;
    up := Sqrt(n);
    
    while j <= up do
        if Divides(j,n) then Return(j) fi;
        j:=j+2;
    od;
    Return(n).;
    
Array eu[16];
eu[1]:=2;
!(eu[1],' ');
for i=2 to 16 do
    eu[i]:=Firstfac(1+Prod[eu[k]]);
    !(eu[i],' ');
od;

  

You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Oforth programming language
You may also check:How to resolve the algorithm Function frequency step by step in the Julia programming language
You may also check:How to resolve the algorithm K-means++ clustering step by step in the Go programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Tiny Craft Basic programming language