Miller–Rabin primality test: Difference between revisions

→‎{{header|Mathematica}}: It would be better to use PowerMod[a, d, n] instead of Mod[Power[a,d] ,n] because of possible overflow. E.g., I got it on MillerRabin[7^561, 25].
(→‎{{header|Mathematica}}: It would be better to use PowerMod[a, d, n] instead of Mod[Power[a,d] ,n] because of possible overflow. E.g., I got it on MillerRabin[7^561, 25].)
Line 932:
<lang Mathematica>MillerRabin[n_,k_]:=Module[{d=n-1,s=0,test=True},While[Mod[d,2]==0 ,d/=2 ;s++]
Do[
a=RandomInteger[{2,n-1}]; x=Mod[PowerPowerMod[a,d] ,n];
If[x!=1,
For[ r = 0, r < s, r++, If[x==n-1, Continue[]]; x = Mod[x*x, n]; ];
Anonymous user