Find the amount of prime numbers between two numbers by using only length and primes
9 次查看(过去 30 天)
显示 更早的评论
Is there any possible way to find the amount of prime numbers between two numbers by using only the commands length and primes? So far I have tried this, but whenever I change the number in the if statements to something larger than 2, the code suddenly won't work.
P = primes(20000);
p=[];
if P >= 10000
p = [p, P];
end
amount = length(p)
0 个评论
采纳的回答
Cris LaPierre
2020-8-20
编辑:Cris LaPierre
2020-8-20
If I can find out the number of primes less than or equal to two different values, then I can use a little math to figure out the number of primes between those two values.
7 个评论
Cris LaPierre
2020-8-20
编辑:Cris LaPierre
2020-8-20
Yes. If I know there are 3 prime numbers <=6, and 8 prime numbers <= 20, then I can figure out the number of primes between 6 and 20 by taking the difference: 8-3 = 5.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!