List primes which are the sum of two consecutive lower primes plus minus one - MATLAB Cody - MATLAB Central

Problem 60967. List primes which are the sum of two consecutive lower primes plus minus one

Difficulty:Rate
Problem statement
Some prime numbers can be written as the sum of two consecutive lower primes plus / minus one :
Like this for example, 7 = 3 + 5 - 1, and 11 = 5 + 7 - 1.
In a vector, list such prime numbers lower than a given -input- positive integer m.
Examples
  • m = 50 => p = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43];
  • m = 100 => p = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 53, 59, 61, 67, 79, 83, 89];
  • m = 200 => p = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 53, 59, 61, 67, 79, 83, 89, 101, 113, 127, 131, 151, 163, 173, 197, 199];
Fobidden functions
  • regexp
  • str2num
  • assignin
  • echo
See also

Solution Stats

76.19% Correct | 23.81% Incorrect
Last Solution submitted on Aug 03, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers11

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!