So I want to know basically how to determine how many prime numbers (integers that can only be divided by 1 and themselves) are contained in a given interval.
Thank you.
So I want to know basically how to determine how many prime numbers (integers that can only be divided by 1 and themselves) are contained in a given interval.
Thank you.
If $a$ and $b$ are integers, with $a$ composite, then the number of primes in the interval $[a,b]$ is the number of primes less than or equal to $b$ minus the number of primes less than or equal to $a$. If $a$ itself is prime, we should account for this by adding that one prime back on. To determine the number of primes less than or equal to a number in mathematica we use the command PrimePi[number].
We can program this as follows:
numPrimes[m_Integer, n_Integer] := If[PrimeQ[m],
PrimePi[n] - PrimePi[m] + 1,
PrimePi[n] - PrimePi[m]
];
numPrimes[11, 31]
numPrimes[10, 31]
numPrimes[555,666]
(* Out:
7
7
20
*)
If you're new to Mathematica, you can also use the WolframAlpha interface, which (in principle) allows you to ask your question in English.

I hope this helps.
Best wishes, $\mathcal H$akim.
PrimePi[7] - PrimePi[5] returns 1, but there are two primes in that closed interval. Second, there's a standard way to post code that allows users to copy it, which an image does not. Finally, why are you using Mathematica's WolframAlpha interface?
– Mark McClure
Feb 22 '14 at 12:42
<code></code> command to write the code. 3) I don't know.
Anyway, thank you so much and cheers!
– Hakim Feb 22 '14 at 12:51= prime pi 33 - prime pi 11, even though that's not standard Mathematica syntax for what you were trying to type.
– Mark McClure
Feb 22 '14 at 15:56