Problem 44305. 5 Prime Numbers
Your function will be given lower and upper integer bounds. Your task is to return a vector containing the first five prime numbers in that range that contain the number five. But, if you can't find at least five such numbers, the function should give up and return -1.
For example, for n_min = 60 and n_max = 1000, the set of prime numbers is:
p = [61,67,71,73,79, … 149,151,157,163, … 241,251,257,263, … 349,353,359,367, … 983,991,997]
This set contains at least five numbers that contain a five; the first five are:
p5 = [151,157,251,257,353]
which is the set that your function should return in this case. If, however, n_max were set at 300, five such numbers do not exist and the function should then give up (return -1).
Solution Stats
Problem Comments
-
2 Comments
Peter Cook
on 20 Oct 2017
I wrote & timed a bunch of sieve type algorithms until I realized the problem was much simpler. Interesting problem.
Gifari Zulkarnaen
on 15 Jan 2021
For all of those having "server error", your code takes too much time on last test. Hint: you don't need to evaluate all numbers between n_min & n_max
Solution Comments
Show commentsGroup

Cody5:Easy
- 31 Problems
- 159 Finishers
- Energy of a photon
- Breaking Out of the Matrix
- The Top 5 Primes
- I Plead the Fifth
- Pentagonal Numbers
- Is this is a Tic Tac Toe X Win?
- Inscribed Pentagon?
- Circle/Pentagon Overlap
- Octoberfest festival
- Polarisation
- Missing five
- ASCII Birthday Cake
- Find the nearest prime number
- Extra safe primes
- 5 Prime Numbers
- Is this is a Tic Tac Toe X Win?
- Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
- MATLAB Counter
- Basic electricity in a dry situation
- How to subtract?
- Pernicious Anniversary Problem
- 5 Prime Numbers
- Is it really a 5?
- The glass half full
- Pi Digit Probability
- A Simple Tide Gauge with MATLAB
- Predicting life and death of a memory-less light bulb
- Write c^3 as sum of two squares a^2+b^2
- Van Eck's Sequence's nth member
- Sums of Multiple Pairs of Triangular Numbers
- Recaman Sequence - I
- Recaman Sequence - II
- Spot the First Occurrence of 5
- Energy of a photon
Problem Recent Solvers439
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!