Problem 525. Mersenne Primes
A Mersenne prime is a prime number of the form M = 2^p - 1, where p is another prime number. For example, 31 is a Mersenne prime because 31 = 2^5 - 1 and both 31 and 5 are prime numbers.
Implement the function isMersenne(x) so that it returns true if x is a Mersenne prime and false otherwise. Your solution should work for all positive integer values of x less than 1,000,000,000 (one billion).
Solution Stats
Problem Comments
-
4 Comments
2047 must turn true... gotta deal with this
No. 2047 is not a Mersenne prime. 2047=23*89, even though it is true that 2047=2^11-1.
Some correct solutions are not logically correct, the test case must be fixed
You need not specify that p is prime in the formula M = 2^p - 1 as it is redundant to do so.
Solution Comments
Show commentsProblem Recent Solvers697
Suggested Problems
-
Find the alphabetic word product
3239 Solvers
-
Flag largest magnitude swings as they occur
669 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1012 Solvers
-
8031 Solvers
-
Calculate the average value of the elements in the array
1079 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!