Elementary number theory

primitive_rootFunction
primitive_root(n::IntegerUnion) -> IntegerUnion

Given a positive integer $n$, return a primitive root modulo $n$. If no such element exists, an error is thrown.

Examples

julia> primitive_root(6)
5
source
coprime_residuesFunction
coprime_residues(n::IntegerUnion) -> Vector

Given an integer $n$, return the list of all $i$ in the range $0 \leq i < |n|$ that are coprime to $n$.

Examples

julia> println(coprime_residues(20))
[1, 3, 7, 9, 11, 13, 17, 19]
source