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

33 Solutions

18 Solvers

Last Solution submitted on Jan 05, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...