Problem 60971. List the twin prime couples

Problem statement
The twin prime couples (p,p') are the ones such that p' = p + 2.
For a given integer n > 1, list the twin prime couples less or equal to n.
Present your result in a m x 2 matrix, where m is the number of twin couples.
Examples
  • n = 10 => p = [3, 5; 5, 7];
  • n = 20 => p = [3, 5; 5, 7; 11, 13; 17 19];
  • n = 100 => p = [3, 5; 5, 7; 11, 13; 17 19; 29, 31; 41, 43; 59, 61; 71, 73];
Forbidden functions / expressions
  • regexp
  • assignin
  • str2num
  • echo
See also

Solution Stats

82.35% Correct | 17.65% Incorrect
Last Solution submitted on Aug 20, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers13

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!