In this tutorial, we will explore the Euclid–Mullin Sequence in C++. The Euclid-Mullin sequence comprises a pair of prime numbers, which are recursively defined. To elaborate further, it initiates with 2 as its initial term and forms a series like: 2, 6, 18, 54, ... Subsequent elements are determined by identifying prime numbers that satisfy a specific condition. In this progression, the succeeding term is ascertained as the smallest prime number that, when divided by the preceding term and incremented by 1, generates the subsequent prime number.
Here is a more technical overview of the process:
- However, no matter the particular term that is chosen in the sequence is always 2.
- In order to find the next term(factor), search for the smallest prime number greater than the last term O(n), and then divide it by the last term plus one and get a prime number.
- This process repeats to create other terms, as illustrated in the subsequent section.
- Starting Point: The sequence beginning is 2, the smallest prime.
- Growth: It naturally increases very fast as the products of the obtained terms are included in it.
- Prime Factorization: It is almost intimately connected to the evaluation of the prime factor of products of the preceding terms whereby each of the terms in the sequence is obtained by multiplying the smallest prime factor of all the preceding terms.
Properties of the Sequence:
Example:
// Program to implement Euclid–Mullin Sequence in C++
#include <bits/stdc++.h>
using namespace std;
// Function to find the smallest prime factor
unsigned long long smallestPrimeFactor(unsigned long long num)
{
//The variable initialization i is 2
unsigned long long i = 2;
// While i <= sqrt(n)
while ((i * i) <= num)
{
// If the number is divisible by 0
if (num % i == 0)
return i;
// The variable increment
i += 1;
}
return num;
}
// Function to print the sequences
void solve_sequence(unsigned long long num)
{
// To store the value for the previous terms
unsigned long long product_val = 1;
// Traverse the prime numbers
unsigned long long i = 0;
while (i < num)
{
// Current term will be the smallest term
// the factor( 1 + product of the all the previous amount)
unsigned long long number = smallestPrimeFactor(product_val + 1);
// The current term
cout << number << " ";
// updation of the product value
product_val = product_val * number;
i += 1;
}
}
//Main section
int main()
{
// Finding the first 20 sequence terms
unsigned long long val = 20;
solve_sequence(val);
}
Output:
2 3 7 43 13 53 5 6221671 38709183810571 5 3 773 31 3 3 3 5 3 3 191020163
Explanation:
In this C++ program, a sequence of prime numbers is generated through a process known as the Euclid–Mullin Sequence. The initial step involves implementing a function called smallestPrimeFactor, which is responsible for determining the smallest prime factor of a specified number. The function operates by examining the divisibility of numbers starting from 2 and continues this process up to the square root of the provided number. If the divisibility check fails for all numbers, a large number is returned, indicating that the input number itself is a prime number.
The progression of the Euclid–Mullin Sequence is managed by the solve_sequence function, which is tasked with factorizing the product of previous terms to reach the value of 1. This recursive process involves computing each term as the smallest prime factor of 1 added to the product of all preceding terms. The iterative nature of this computation ensures the continuous generation of prime numbers within the sequence.
To facilitate this sequence generation, the program begins by defining the function smallestPrimeFactor, which plays a crucial role in identifying the smallest prime factor of a given number. By systematically checking divisibility starting from 2 and iterating through numbers up to the square root of the input, this function effectively contributes to the iterative generation of prime numbers in the Euclid–Mullin Sequence.
The main function is called solve_sequence, and it takes a parameter to decide the number of terms it will generate. With this method, it is easy to build the Euclid–Mullin Sequence due to the method of prime factorization and multiplication based on the list of different prime numbers.
Conclusion:
In summary, the Euclid Mullin sequence represents a mathematical series that initiates from the smallest prime number, which is 2. Subsequent terms are derived by identifying the prime factor of the expression 1 plus the product of all preceding terms. Each term within this sequence is a prime number, and I have observed significant exponential expansion due to the multiplication of these prime numbers. This approach to generating the sequence emphasizes the intricate connections among the foundational elements involved in determining its properties, specifically prime numbers, the process of factorization, and iterative computations. Furthermore, this sequence serves not only as a mathematical exercise but also demonstrates the complexity of computational procedures associated with prime numbers, as all terms in the sequence are interconnected. The simplicity of the rules governing this sequence leading to the emergence of fractal patterns underscores how shapes evolve, divide, and interact within number theory, rendering it a timeless example in exploring growth principles within the realm of mathematical sciences.