Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The algorithm you're following is called the <a href="http://en.wikipedia.org/wiki/Fermat_primality_test" rel="nofollow noreferrer">Fermat primality test</a>. However, there are several problems with your explanation:</p> <ul> <li><p>You say "confirm that gcd(a,p) is &lt; 1". This doesn't make sense as the gcd will never be less than one. What you can check is that gcd(a,p)==1. If it isn't 1, then p is not a prime. This can detect Carmichael numbers, but may have only a small chance to do so.</p></li> <li><p>The way the test is conducted, is that for a certain value of p, you pick several random values of a and check if a ^ (p-1) % p == 1. If one of them is not 1, then p isn't prime. The more values of a you pick, the better your accuracy.</p></li> <li><p>You certainly can't check for <em>all</em> values of x as you say - since there are too many to check.</p></li> <li><p>There is a fast way to perform modular exponentiation, even for large base and exponent. See the <a href="http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method" rel="nofollow noreferrer">Wikipedia article</a>. You will still need a method to perform multiplication and modulo on large integers.</p></li> <li><p>The Sieve of Eratosthenes is only useful for finding small primes.</p></li> <li><p>This test may incorrectly determine that Carmichael numbers are prime. Other algorithms such as <a href="http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test" rel="nofollow noreferrer">Rabin-Miller</a> don't have this problem.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload