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
Problem Comments
-
2 Comments
ChrisR
on 26 Jun 2025
For a related problem see #52881.
Nicolas Douillet
on 26 Jun 2025
Yes, thank you Chris.
Solution Comments
Show commentsProblem Recent Solvers19
Suggested Problems
More from this Author42
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!