# Revision history [back]

There are various ways to compute the inverse of a number modulo some other number.

They include

• using the function inverse_mod.
• working in the ring of integers modulo n.

Using inverse_mod:

sage: n = 14
sage: a = 5
sage: b = inverse_mod(a, n)

sage: b
3
sage: a * b
15
sage: (a * b) % n
1


Using the ring of integers modulo n:

sage: n = 14
sage: A = Zmod(n)
sage: a = A(5)
sage: a
5

sage: b = a^-1
sage: b
3
sage: b * a
1