Find the first occurence of a given gap between two consecutive prime numbers - MATLAB Cody - MATLAB Central

Problem 60940. Find the first occurence of a given gap between two consecutive prime numbers

Difficulty:Rate
Problem statement
Given a gap Δ= p' - p between the two consecutive prime numbers p and p', find its first occurence, f.
Examples
  • If , f=2, since 5 - 3 = 2, and 3 is the 2nd prime;
  • If , f=4, since 11 - 7 = 4, and 7 is the 4th prime;
  • If , f=9, since 29 - 23 = 6, and 23 is the 9th prime;
If Δ neither equals an even positive integer nor equals 1 your function should return the empty set : f = [];
See also

Solution Stats

42.86% Correct | 57.14% Incorrect
Last Solution submitted on Aug 03, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers15

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!