필터 지우기
필터 지우기

primes function

조회 수: 3 (최근 30일)
Sean Smith
Sean Smith 2011년 9월 18일
편집: Walter Roberson 2017년 1월 31일
Is there a way to use the prime function to find the prime numbers between two numbers? I want to find the prime numbers between 20,000 and 10,000 and save that to a variable. primes(20000) gives me them all the way to zero and if i try to subtract primes(20000) and primes(10000) it won't let me because there not the same size. Any ideas? Thanks.
  댓글 수: 1
Jack Garvey
Jack Garvey 2017년 1월 31일
편집: Walter Roberson 2017년 1월 31일
1.) make array of range: range = [10000:1:20000]
2.) create logical array of (range) displaying which numbers are prime: isprime(range)
3.) find total amount of prime numbers within that range: number_of_primes = sum(isprime(range))
4.) i got the answer of 1033 prime numbers between 10K and 20K

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2011년 9월 18일
setdiff(primes(20000),primes(10000))

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2011년 9월 18일
k = 1e4:2e4;
out = k(isprime(k));
variant
prms = primes(20000);
out = prms(prms>=10000);

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by