Anonymous user
Miller–Rabin primality test: Difference between revisions
→{{header|Icon}} and {{header|Unicon}}
No edit summary |
|||
Line 715:
The following code works in both languages:
<lang unicon>procedure main()
every
end
procedure primeTest(n, k)
if n = 2 then return
if n%2 = 0 then
s := 0
d := n-1
Line 729:
if x = (1 | (n-1)) then next
every (1 to s-1, x := (x^2)%n) do {
if x = 1 then
if x = n-1 then break next
}
}
return
end</lang>
Sample run:
<pre>->mrpt
907 911 919 937 941 947 953 967 971 977 983 991 997
-></pre>
|