Problem 60946. Fermat primes

Historical context
The french mathematician Pierre de Fermat found the formula to find some prime numbers. He thought / conjectured all these numbers where primes, but P(5) is actually the first not prime Fermat number.
Problem statement
For a given integer m, , list the Fermat prime numbers less or equal to m in a vector fp. Also compute their frequency / ratio f compare to all the primes in the same range. If , your function should return fp = [] and f = 0.
Examples
  • If m = 10 then fp = [3, 5] and f = 2/3 since 3 = P(0), 5 = P(1), and there are in total three primes in the range [3; 10] ;
  • If m = 300 then fp = [3, 5, 17, 257] and f = 4/61 since 3 = P(0), 5 = P(1), 17 = P(2), 257 = P(3) and there are in total 61 prime numbers in the range [3; 300] ;
  • If m = 2 then fp = [] and f = 0;
Tip
here.
Fobidden functions
  • regexp
  • assignin
  • str2num
See also

Solution Stats

56.52% Correct | 43.48% 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!