Skip to content

Elementary number theory

primitive_root Function
julia
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
julia> primitive_root(6)
5
source
coprime_residues Function
julia
coprime_residues(n::IntegerUnion) -> Vector

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

Examples

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