Problem 60947. Euclid primes

Historical context
Euclid, the greek mathematician proved at his time that the prime numbers set is an infinite. By the way he built some numbers, the Euclid numbers, an infinity of which are thought to be prime (it is still a conjecture). These numbers write themselves as e(n) = 1 + the nth primorial : (notre that 2 and 3 are the two first Euclid primes)
Problem statement
For a given integer m, m >= 2, list the Euclid prime numbers less or equal to m in a vector ep. Also compute their frequency / ratio f compare to all the primes in the same range. If , your function should return ep = [] and f = 0.
Examples (check the tests for more)
  • If m = 10 then ep = [2, 3, 7] and f = 3/4 since 5 is the only prime number over the four ones less than 10 which is not an Euclid prime;
  • If m = 300 then ep = [2, 3, 7, 31, 211] and f = 5/62 since 2 and 3 are Euclid primes, 7 = 2x3+1, 31 = 2x3x5+1, 211 = 2x3x5x7+1, and there are in total 62 prime numbers in the range [2; 300] ;
  • If m = 1 then ep = [] and f = 0;
Tip
here.
Fobidden functions
  • regexp
  • str2num
  • assignin
See also

Solution Stats

59.09% Correct | 40.91% Incorrect
Last Solution submitted on Aug 17, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers12

Suggested Problems

More from this Author42

Community Treasure Hunt

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

Start Hunting!