How to resolve the algorithm Euclid-Mullin sequence step by step in the ALGOL W programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Euclid-Mullin sequence step by step in the ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin % find elements of the Euclid-Mullin sequence: starting from 2, %
% the next element is the smallest prime factor of 1 + the product %
% of the previous elements %
integer product;
write( "2" );
product := 2;
for i := 2 until 8 do begin
integer nextV, p;
logical found;
nextV := product + 1;
% find the first prime factor of nextV %
p := 3;
found := false;
while p * p <= nextV and not found do begin
found := nextV rem p = 0;
if not found then p := p + 2
end while_p_squared_le_nextV_and_not_found ;
if found then nextV := p;
writeon( i_w := 1, s_w := 0, " ", nextV );
product := product * nextV
end for_i
end.
You may also check:How to resolve the algorithm Hello world/Text step by step in the SNUSP programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the GML programming language
You may also check:How to resolve the algorithm Comments step by step in the Elm programming language
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the Batch File programming language
You may also check:How to resolve the algorithm Delete a file step by step in the Retro programming language