List the Euclid numbers - MATLAB Cody - MATLAB Central

Problem 54620. List the Euclid numbers

Difficulty:Rate
Euclid proved that the number of primes is infinite with the following argument. Suppose the primes form a finite set p_1, p_2, p_3,...p_n. Compute N = p_1 p_2 p_3...p_n + 1. This number N is either prime or composite.
If it is prime, then the original supposition that the primes form a finite set is false. For example, if we assume that the only primes are 2, 3, and 5, then N = 31, which is prime. Therefore, 31 should be in the set of primes.
If N is composite, then there must be another prime number because N is not divisible by any of the primes in the original set. For example, if we assume the only primes are 2, 3, 5, and 31, then N = 931 = 7^2 19. Therefore, 7 and 19 should be in the set as well.
Either way, a contradiction is reached, and the set of primes must be infinite. In other words, we can always add another prime to the set.
Write a function to return the nth Euclid number p_1 p_2 p_3...p_n + 1 as a character string, where is the nth prime. Take the zeroth Euclid number to be 2.

Solution Stats

47.37% Correct | 52.63% Incorrect
Last Solution submitted on Dec 02, 2024

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers8

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!