Problem 981. Find nearest prime number less than input number
Find nearest prime number less than input number.
For example: if the input number is 125, then the nearest prime number which is less than this number is 113.
Be careful, in that 1 is not a prime number. So there is NO prime less than 2.
Solution Stats
Problem Comments
-
8 Comments
I removed the test case where n==2, since 1 is indeed not a prime number. I also added a random test case, so the problem is not so easily cooked by knowing all the test cases.
1 is indeed prime. Aliens will laugh at us when we say it is not. 1 causes all sorts of problems by not being prime. As many as it causes by being prime. It is already an exception in thousands of mathematical theorems. Why mathematicians chose this one theorem to not include 1 as an exception is beyond me.
1 is a unit (in the ring-theoretic sense), and units are excluded from the definitions of prime elements and irreducible elements in rings. I'm not a mathematician and don't have more than a basic undergrad exposure to abstract rings, but there surely is a good reason. Any mathematicians reading this who can shed on light on this?
Solution Comments
Show commentsProblem Recent Solvers861
Suggested Problems
-
Make the vector [1 2 3 4 5 6 7 8 9 10]
50167 Solvers
-
738 Solvers
-
Back to basics - mean of corner elements of a matrix
427 Solvers
-
1712 Solvers
-
1388 Solvers
More from this Author11
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!