Message Boards Message Boards

0
|
7148 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Find the smallest prime number greater than 5000?

Posted 8 years ago

I ask a few beginner level questions here frequently, not only because I am a beginner in Mathematica but sometimes these concepts are just as important as the large concepts.

I am trying to find the smallest prime number greater than 5000. here is my code:

PrimeQ[Range[5000, 5050]]

I could test each term if I wanted, like this PrimeQ[5000], PrimeQ[5001].. ok that's tedious

I could also produce a list of True, False(like I have in my code above) which correspond to the numbers in my range but I would still need to count to find what smallest number that is.. Is it possible to list both the number along with true or false? Does this make sense? my code only produces a list of true and falses.

POSTED BY: Brandon Davis
5 Replies
Posted 8 years ago

Well I figured it out..

Clear[a]; a[m_] := Table[verprime[k ], {k, 1000, m}]

a[1050] // TableForm

thanks for any other alternatives!!

POSTED BY: Brandon Davis
Posted 8 years ago
In[24]:= NextPrime[5000]

Out[24]= 5003
POSTED BY: David Keith
Posted 8 years ago

wow its that easy huh?..this is great!

thank you david

POSTED BY: Brandon Davis

The Table function is great for this:

l = Table[{i, PrimeQ[i]}, {i, 5000, 5050}]

Next, you might want to create a list of all of the primes in your range. You can do that with this, though there may be better ways:

primes = Cases[l, {_, True}][[All, 1]]

And, you can now find the smallest:

Min[primes]
POSTED BY: Tim Mayes
Posted 8 years ago

I just found a similar way using table.

thanks for the help Tim

POSTED BY: Brandon Davis
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract