Skip to content

Instantly share code, notes, and snippets.

View milanboers's full-sized avatar
🙃

Milan Boers milanboers

🙃
View GitHub Profile
@milanboers
milanboers / MillerRabin.scala
Last active May 1, 2016 05:12
Deterministic version of the Miller-Rabin primality test for Scala
//MillerRabin.scala
import scala.language.implicitConversions
object MillerRabin {
implicit class MillerRabin(n: Long) {
private lazy val asl : Array[BigInt] = if (n < 2047L) Array(2L)
else if (n < 1373653L) Array(2L, 3L)
else if (n < 9080191L) Array(31L, 73L)
else if (n < 25326001L) Array(2L, 3L, 5L)
else if (n < 3215031751L) Array(2L, 3L, 5L, 7L)