Given a positive integer 'n', the task is to find a prime number greater than or equal to 'n'.
Example 1
If given 'n' is 10, then the closest prime number greater than 10 is 11 at a distance of 1. So 11 must be returned.
Example 2
If the given 'n' is 17, then the closest prime number is itself at a distance of 0. So 17 must be returned.
The returned prime number must be greater than or equal to 'n'.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers104
Suggested Problems
-
Sum of first n terms of a harmonic progression
519 Solvers
-
Find the maximum number of decimal places in a set of numbers
3554 Solvers
-
698 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
894 Solvers
-
Find the position of first minimum value in an integer array with numbers
185 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
From test case 2, it seems that you are asking for the closest prime number no less than n. Please clarify this ambiguity in the problem. Otherwise, the answer to test case 2 is 19 (not 23), which is the closest prime number to 20.
Final statement in problem statement disagrees with Case #1 of n=3.
I made a few quick edits.
I suggest to update this problem with big primes.