Problem 60970. Check p = 6n +/- 1, the generic formula for odd prime numbers greater than 3

Problem statement
For all odd prime number p greater than 3, there exists a positive integer n, such that p = 6n +/- 1 :
Check this formula for some given odd primes in a vector by computing n for each p.
Examples
  • p = 17 => n = 3;
  • p = 19 => n = 3;
  • p = [5, 7, 11, 13, 17, 19] => n = [1, 1, 2, 2, 3, 3];
  • p = [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
=> n = [1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16];
Forbidden functions / expressions
  • regexp
  • assignin
  • str2num
  • echo
See also

Solution Stats

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

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

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!