Jump to content

Miller–Rabin primality test: Difference between revisions

Line 867:
<pre>java MillerRabinPrimalityTest 123456791234567891234567 1000000
123456791234567891234567 is probably prime</pre>
 
=={{header|Mathematica}}==
<lang Mathematica>MillerRabin[n_,x1_]:=Module[{d=n-1,s=0,test=True},While[Mod[d,2]==0 ,d/=2 ;s++]
Do[
a=RandomInteger[{2,n-1}]; x=Mod[Power[a,d] ,n];
If[x!=1,
For[ r = 0, r < s, r++, If[x==n-1, Continue[]]; x = Mod[x*x, n]; ];
If[ x != n-1, test=False ];
];
,{x1}];
Print[test] ]
 
Example output (not using the PrimeQ builtin):
MillerRabin[17388,10]
->False</lang>
 
=={{header|PARI/GP}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.