Problem 60944. Ulam primes first formula

Historical context
The polish-american mathematician Stanislaw Ulam found the formula to give the first 760 prime numbers not given by Euler's formula.
Problem statement
For a given integer m, m >= 1847, list the Ulam prime numbers less or equal to m in a vector up. 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 1847, your function should return up = [] and f = 0.
Examples
  • If m = 1847 then up = 1847 and f = 1 since 1847 = P(0) and it is the only prime number m greater or equal and less or equal to 1847;
  • If m = 3000 then up = [1847, 2203, 2393, 2591, 2797] and f = 5/148 since 1847 = P(0), 2203 = P(2), 2393 = P(3), 2591 = P(4), 2797 = P(5), and there are in total 30 prime numbers in the range [1847; 3000] ;
  • If m = 1823 then up = [] and f = 0;
Tip
n is less or equal to 2000 here.
Fobidden functions
  • regexp
  • assignin
  • str2num
See also

Solution Stats

53.85% Correct | 46.15% 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!