Problem 2910. Mersenne Primes vs. All Primes
A Mersenne prime (M) is a prime number of the form M = 2^p - 1, where p is another prime number. Problem 525 asks the user to determine if a number is a Mersenne prime. In this problem, you are tasked with returning the number of primes numbers below the input number, n, that are Mersenne primes and the fraction of all primes below that input number that the Mersenne primes represent.
For example, for n = 100, there are 25 primes numbers: 2, 3, 5, 7, ..., 89, 97. As far as Mersenne primes go, there are only three that are less than 100: 2^2 - 1 = 3, 2^3 - 1 = 7, and 2^5 - 1 = 31. The corresponding fraction would be 3/25.
Solution Stats
Problem Comments
-
1 Comment
Hello Grant,
I don't know if it's a lot of work but it could be a good idea to add a Prime Numbers group 2 with more difficult problems. I think about beautiful Ned's problems (primes ladders, Longest prime diagonal, Twins in a window ...).
Solution Comments
Show commentsGroup

Introduction to MATLAB
- 23 Problems
- 8330 Finishers
- Add two numbers
- Find the sum of all the numbers of the input vector
- Maximum value in a matrix
- Return area of square
- Finding Perfect Squares
- Make the vector [1 2 3 4 5 6 7 8 9 10]
- Generate a vector like 1,2,2,3,3,3,4,4,4,4
- Triangle Numbers
- Length of the hypotenuse
- Select every other element of a vector
- Reverse the vector
- Column Removal
- Swap the input arguments
- Swap the first and last columns
- Check if number exists in vector
- Determine whether a vector is monotonically increasing
- Getting the indices from a vector
- Create times-tables
- Return the first and last characters of a character array
- Number of 1s in a binary string
- Make a random, non-repeating vector.
- Magic is simple (for beginners)
- Sum all integers from 1 to 2^n
Problem Recent Solvers723
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!