Problem 42749. Find the nearest prime
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
-
4 Comments
Show
1 older comment
Richard Zapor
on 25 Feb 2016
Final statement in problem statement disagrees with Case #1 of n=3.
Ned Gulley
on 25 Feb 2016
I made a few quick edits.
Jean-Marie Sainthillier
on 29 Feb 2016
I suggest to update this problem with big primes.
Solution Comments
Show commentsProblem Recent Solvers101
Suggested Problems
-
Number of 1s in the Binary Representation of a Number
456 Solvers
-
217 Solvers
-
292 Solvers
-
490 Solvers
-
846 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!