Lucas-Lehmer test: Difference between revisions

Content added Content deleted
Line 2,283: 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 very high.
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 very high.


<syntaxhighlight lang="langur">val .isPrime = f .i == 2 or
<syntaxhighlight lang="langur">val .isPrime = fn(.i) .i == 2 or
.i > 2 and not any f(.x) .i div .x, pseries 2 .. .i ^/ 2
.i > 2 and not any fn(.x) .i div .x, pseries 2 .. .i ^/ 2


val .isMersennePrime = f(.p) {
val .isMersennePrime = fn(.p) {
if .p == 2: return true
if .p == 2: return true
if not .isPrime(.p): return false
if not .isPrime(.p): return false
Line 2,296: Line 2,296:
}
}


writeln join " ", map f $"M\.x;", filter .isMersennePrime, series 2300</syntaxhighlight>
writeln join " ", map fn(.x) $"M\.x;", filter .isMersennePrime, series 2300</syntaxhighlight>


{{out}}
{{out}}