Anonymous user
Miller–Rabin primality test: Difference between revisions
→{{header|Tcl}}: slightly less contorted code
(→{{header|Tcl}}: slightly less contorted code) |
|||
Line 406:
if {$n <= 3} {return true}
if {$n % 2 == 0} {return false}
# write n
set d [expr {$n - 1}]
set s 0
Line 414:
incr s
}
while {$k > 0} {
incr k -1
set a [expr {2 + int(rand()*($n - 4))}]
set x [expr {($a ** $d) % $n}]
if {$x == 1 || $x == $n - 1}
for {set r 1} {$r < $s} {incr r} {
set x [expr {($x ** 2) % $n}]
if {$x == 1} {return false}
if {$x == $n - 1}
}
▲ return false
}
return true
|