AFN's blog

By AFN, history, 7 years ago, In English

Hi everyone!

I'm really facing problems in when to use modular inverse. I know that you should use it when calculating the following

(a / b)%p = (a * bp - 2)%p [Only when p is prime]

I know there is a case when subtracting, but I don't know how you do it exactly, can you tell me how? And are there any other cases?

Thanks in advance.

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Remember, the modular inverse of some number a modulo m, is a number b such that:

a·b ≡ 1 (mod m)

That's why you use it when you have to do divisions modulo some number .

However, a number a has inverse modulo m iff they are coprime (gcd(a, m) = 1)

If m is prime, you can apply the formula you mentioned in your post. Otherwise, you have to find the modular inverse using another method (for example, Extended GCD)

I don't know what do you mean with "case when subtracting". If you have to perform a subtraction between two numbers modulo m, there's no need to use the modular inverse.