Lucas-Lehmer test: Difference between revisions

 
Line 2,283:
It is theoretically possible to test to the 47th Mersenne prime, as stated in the task description, but it could take a while. As for the limit, it would be extremely high.
 
<syntaxhighlight lang="langur">val .isPrime = fn(.i) {
val isPrime = fn(i) {
.i == 2 or .i > 2 and
not any(fn .x: .i div .x, pseries (2 .. .i ^/ 2))
}
 
val .isMersennePrime = fn(.p) {
if .p == 2: return true
if not .isPrime(.p): return false
 
val .mp = 2 ^ .p - 1
for[.s=4] of 3 .. .p {
.s = (.s ^ 2 - 2) rem .mp
} == 0
}
 
writeln join (" ", map (fn .x: "M{{.x}}", filter .(isMersennePrime, series (2300))))
</syntaxhighlight>
 
1,007

edits