Problem 981. Find nearest prime number less than input number
Solution Stats
Problem Comments
-
8 Comments
1 isn't a prime number
agree @bmtran...
You should correct the test suite. 1 isn't a prime number.
Correct the test suite 1 is not prime number.
1 is not a prime number, in order to fulfill with the fundamental theorem of arithmetic:
https://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic
https://en.wikipedia.org/wiki/Prime_number#Primality_of_one
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 Solvers583
Suggested Problems
-
Project Euler: Problem 3, Largest prime factor
1211 Solvers
-
326 Solvers
-
Generate N equally spaced intervals between -L and L
813 Solvers
-
There are 10 types of people in the world
841 Solvers
-
Height of a right-angled triangle
1391 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!