How to find first ten prime numbers that are greater than 4?

11 visualizaciones (últimos 30 días)
Hi,
How am I going to make an array that consists of first 10 prime numbers that are greater than 4 as follows?
a=[5 7 11 13 17 19 23 29 31 37]
Thank you.

Respuesta aceptada

Matz Johansson Bergström
Matz Johansson Bergström el 4 de Oct. de 2014
You could do it like this
x = primes(100); %pick primes smaller than, say 100
x = x(x>4); %pick the ones larger than 4
x(1:10) %pick the first ten of those
  1 comentario
Matz Johansson Bergström
Matz Johansson Bergström el 4 de Oct. de 2014
Editada: Matz Johansson Bergström el 4 de Oct. de 2014
If you want to pick the first n primes larger than k, then there might be some way to first estimate the upper bounds of the number in the function primes you need, by using the "prime-counting function", see http://en.wikipedia.org/wiki/Prime-counting_function. In this case you also have to account for the shifting of k ofcourse. So it's not trivial in that case.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete Math en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by