How to find first ten prime numbers that are greater than 4?
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Matz Johansson Bergström
2014년 10월 4일
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
Matz Johansson Bergström
2014년 10월 4일
편집: Matz Johansson Bergström
2014년 10월 4일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!