Miller–Rabin primality test: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
|||
Line 357: | Line 357: | ||
y := i&1 ? mod(y*z,m) : y, z := mod(z*z,m), i >>= 1 |
y := i&1 ? mod(y*z,m) : y, z := mod(z*z,m), i >>= 1 |
||
Return y |
Return y |
||
}</lang> |
}</lang> |
||
=={{header|bc}}== |
=={{header|bc}}== |
||
Line 431: | Line 431: | ||
} |
} |
||
quit</lang> |
quit</lang> |
||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
{{trans|bc}} |
{{trans|bc}} |
||
Line 687: | Line 688: | ||
}</lang> |
}</lang> |
||
Inspiration from http://stackoverflow.com/questions/4424374/determining-if-a-number-is-prime |
Inspiration from http://stackoverflow.com/questions/4424374/determining-if-a-number-is-prime |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
Line 2,863: | Line 2,862: | ||
End Function |
End Function |
||
</lang> |
</lang> |
||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |
||
<lang Mathematica>MillerRabin[n_,k_]:=Module[{d=n-1,s=0,test=True},While[Mod[d,2]==0 ,d/=2 ;s++] |
<lang Mathematica>MillerRabin[n_,k_]:=Module[{d=n-1,s=0,test=True},While[Mod[d,2]==0 ,d/=2 ;s++] |
||
Line 3,610: | Line 3,610: | ||
for (1..100) { say if is_prime_mr($_) }</lang> |
for (1..100) { say if is_prime_mr($_) }</lang> |
||
Math::Pari can be used in a fashion similar to the Pari/GP custom function. The builtin accessed using a second argument to <tt>ispseudoprime</tt> was added to a later version of Pari (the Perl module uses version 2.1.7) so is not accessible directly from Perl. |
Math::Pari can be used in a fashion similar to the Pari/GP custom function. The builtin accessed using a second argument to <tt>ispseudoprime</tt> was added to a later version of Pari (the Perl module uses version 2.1.7) so is not accessible directly from Perl. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 4,252: | Line 4,207: | ||
(prime? 4547337172376300111955330758342147474062293202868155909489) ;-> outputs true |
(prime? 4547337172376300111955330758342147474062293202868155909489) ;-> outputs true |
||
</lang> |
</lang> |
||
⚫ | |||
(formerly Perl 6) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|REXX}}== |
=={{header|REXX}}== |