Problem 60941. Prime numbers which are the difference of two consecutive cubes

Problem statement
Given a positive integer n greater than 2, find the prime numbers less or equal to n and which are the difference of the cubes of two consecutive integers and store them in ascending order in a row vector u. Also, compute the frequency / ratio f of those numbers compare to all the prime numbers less or equal to n.
Examples
  • If n = 100, then u = [7, 19, 37, 61], and f = 4/25, since 7 = 2^3 - 1^3, 19 = 3^3 - 2^3, 37 = 4^3 - 3^3, 61 = 5^3 - 4^3, and there are 25 prime numbers less or equal to 100;
  • If n = 400, then u = [7, 19, 37, 61, 127, 271, 331, 397], and f = 8/78, since 127 = 7^3 - 6^3, 271 = 10^3 - 9^3, 331 = 11^3 - 10^3, 397 = 12^3 - 11^3, and there are 78 prime numbers less or equal to 400;
Tips
Forbidden functions
  • regexpr
  • str2num
  • assignin
See also

Solution Stats

68.97% Correct | 31.03% Incorrect
Last Solution submitted on Sep 10, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers19

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!