You may be thinking of Euclid's proof that there are in infinite number of primes. It doesn't give you the next largest prime, or even guarantee that the result is a prime. But it does force the existence of some larger prime. You don't really need to multiply just the previous primes, you can multiply together all smaller numbers. So if you have a prime p, and you take q = 1 + p!, then either q is a prime itself, or is a multiple of some prime larger than p. But as mentioned by others, there is no smart way of getting the next largest prime. Just brute-force all the larger odd numbers, or use Eratosthenes as you said.

Update: You may be interested in reading the recent findings about primality testing being possible in polynomial-time: PRIMES is in P. But for a much more efficient (but probabilistic) algorithm for testing primality, search Google for the Miller-Rabin primality test. AFAIK it's the most commonly used algorithm, and it's a lot better then checking all the possible divisors. Unfortunately, it uses a fair amount of number theory ;)

blokhead


In reply to Re: Finding the next larger prime. by blokhead
in thread Finding the next larger prime. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.