Skip to content

Commit

Permalink
ModInts example: use invmod instead of gcdx
Browse files Browse the repository at this point in the history
Ref: 331eb3f
  • Loading branch information
jiahao committed Oct 5, 2014
1 parent 0388647 commit 7dd704b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions examples/modint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Base.promote_rule{n}(::Type{ModInt{n}}, ::Type{Int}) = ModInt{n}
Base.show{n}(io::IO, k::ModInt{n}) = print(io, "$(k.k) mod $n")
Base.showcompact(io::IO, k::ModInt) = print(io, k.k)

function Base.inv{n}(a::ModInt{n})
thegcd, x = gcdx(a.k, n)
thegcd==1 ? ModInt{n}(x) : error("Inverse of $(a.k) mod $n doesn't exist")
end

Base.inv{n}(a::ModInt{n}) = ModInt{n}(invmod(a.k, n))

end # module

0 comments on commit 7dd704b

Please sign in to comment.