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
Show
1 older comment
John D'Errico
on 22 Feb 2018
No. 2047 is not a Mersenne prime. 2047=23*89, even though it is true that 2047=2^11-1.
Minh-Khoi LE
on 22 Feb 2022
Some correct solutions are not logically correct, the test case must be fixed
Brandon
on 30 May 2023
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 commentsGroup

KR SA Joint & Collaborative Cody Event
- 35 Problems
- 2 Finishers
- Convert from Fahrenheit to Celsius
- Area of an equilateral triangle
- Find the sum of all the numbers of the input vector
- Function composition
- Sunday bonus
- Sum of odd numbers in a matrix
- Find the position of first minimum value in an integer array with numbers
- Sum of first n positive integers
- Determinant of a 3x3 Matrix
- Draw a '0' in a one matrix!
- Mersenne Primes
- Select every other element of a vector
- Find a Pythagorean triple
- Is this triangle right-angled?
- ~~~~~~~ WAVE ~~~~~~~~~
- Create an n-by-n null matrix and fill with ones certain positions
- Find max
- Calculate the derivative of a polynomial
- Extract part elements of matrix into one new matrix
- Triangle sequence
- 2048 Next Move
- Which doors are open?
- matrix zigzag
- Which values occur exactly three times?
- Binary numbers
- Counting Money
- Shuffle
- With apologies to William Blake
- MatCAT - Reconstruct X from Its X-rays
- Solve an ODE: equation B
- Longest run of consecutive numbers
- Vector push
- Five-dimensional maze
- The sliding puzzle: 3D
- One track five lanes
Problem Recent Solvers840
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!