Miller–Rabin primality test: Difference between revisions

→‎{{header|PARI/GP}}: split into subsections
m (→‎{{header|PARI/GP}}: make functions use the same interface)
(→‎{{header|PARI/GP}}: split into subsections)
Line 767:
 
=={{header|PARI/GP}}==
===Built-in test:===
<lang parigp>MR(n,k)=ispseudoprime(n,k);</lang>
 
===Custom function:===
<lang parigp>sprp(n,b)={
my(s = valuation(n-1, 2), d = Mod(b, n)^(n >> s));
Line 788:
};</lang>
 
===Deterministic version===
A basic deterministic test can be obtained by an appeal to the [[wp:Extended Riemann hypothesis|ERH]] (as proposed by Gary Miller) and a result of Eric Bach. Calculations of Jan Feitsma can be used to speed calculations below 2<sup>64</sup> (by a factor of about 250).
<lang parigp>A006945=[9, 2047, 1373653, 25326001, 3215031751, 2152302898747, 3474749660383, 341550071728321, 341550071728321, 3825123056546413051];
Miller(n)={
if (n%2 == 0, return(n == 2)); \\ Handle even numbers