Euler primes - MATLAB Cody - MATLAB Central

Problem 60942. Euler primes

Difficulty:Rate
Historical context
The great swiss mathematician Leonhard Euler found the formula to give some prime numbers.
Problem statement
For a given integer m, m >= 41, list the Euler 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 m is not a positive integer greater or equal to 41, your function should return ep = [] and f = 0.
Examples (check the tests for more)
  • If m = 41 then ep = 41 and f = 1 since 41 = P(0) and it is the only prime number m greater or equal and less or equal to 41;
  • If m = 100 then ep = [41, 43, 47, 53, 61, 71, 83, 97] and f = 8/13 since 41 = P(0), 43 = P(1), 47 = P(2), 53 = P(3), 61 = P(4), 71 = P(5), 83 = P(6), and 97 = P(7), and in total there are 13 prime numbers in the range [41; 100] ;
  • If m = 19 then ep = [] and f = 0;
Tip
n is less or equal to 107 here.
Fobidden functions
  • regexp
  • str2num
  • assignin
Please don't forget to like if you appreciated solving my problem :-)

Solution Stats

62.5% Correct | 37.5% Incorrect
Last Solution submitted on Jul 10, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers12

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!