What is the simplest function that generates a list of primes up to the argument? Its not hard to come up with such a function, for instance:
foo[n_] := Block[{A = {}, p = 2},
While[p < n, A = Append[A, p]; p = NextPrime[p]];
A]
However, this seems overly messy. I would like to do something like
foo[n_] := Table[Prime[i], {i,2,???}]
Where ??? is the index ofNextPrime[n,-1]
. Is this possible?
For example
f[x_] := Prime[Range@PrimePi@x]
Usage
Grid[Table[{x, f[x]}, {x, 13, 20}], Frame -> All]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With