Prime number handling of various sorts.
Examples
iex> Primacy.is_prime?(61)
true
iex> Primacy.primes_near(600, count: 3)
[599, 601, 607]
Summary
Functions
Prime check.
Inputs below 4_000_000 are settled by trial division; larger inputs use Miller-Rabin, which is deterministic below 2^64. Confirming a prime at or above 2^64 falls back to exhaustive trial division and can take several seconds.
Examples
iex> Primacy.is_prime?(61)
true
iex> Primacy.is_prime?(62)
false
Generate a list of primes near a given number
Options:
count: how long a list to produce? (default: 1)dir::below,:above,:around(default::around)
Scanning downward stops at 2, so fewer than count primes may be
returned when there are not enough primes below the starting point.
A count of zero or less returns an empty list.
Examples
iex> Primacy.primes_near(600)
[601]
iex> Primacy.primes_near(600, count: 10)
[571, 577, 587, 593, 599, 601, 607, 613, 617, 619]
iex> Primacy.primes_near(600, count: 10, dir: :below)
[541, 547, 557, 563, 569, 571, 577, 587, 593, 599]
iex> Primacy.primes_near(3, count: 5, dir: :below)
[2, 3]