Блог пользователя Kefrov

Автор Kefrov, история, 3 месяца назад, По-английски

This short video serves as proof for the following mathematical statement:


$$$ \displaystyle \textbf{(H)} : \frac{a}{b} \mod m = a \cdot b^{-1} \mod m $$$
$$$ \displaystyle \text{Such that } b \mid a \text{ and} \gcd(b, m) = 1 $$$


1999F - Expected Median urged me to study modular arithmetic, specifically modular division. However, no document or video I found contained this proof, so I tried to prove it myself. It's not hard, so maybe that's why I couldn't find it, or maybe I didn't search well enough.

Anyway, often we are tasked with calculating a large number modulo $$$10^9 + 7$$$. For this, we need to perform some modular arithmetic tricks, but things get complicated when trying to perform division, like in the case of the binomial coefficient $$$\binom{n}{p}$$$. The reason for this is that when applying modulo to integers $$$a$$$ and $$$b$$$ such that $$$b \mid a$$$, there is no guarantee that $$$(b \mod m) \mid (a \mod m)$$$. So to actually calculate $$$\frac{a}{b} \mod m$$$, we need to use the Modular Multiplicative Inverse of $$$b$$$ as shown in the statement above.

We can easily find $$$b^{-1}$$$ using the Extended Euclidean Algorithm in $$$O(\log m)$$$:

Code

It makes more sense to prove that $$$(\frac{a}{b} \mod m = r_a \cdot r_b^{-1} \mod m)$$$ such that $$$(r_a = a \mod m)$$$ and $$$(r_b = b \mod m)$$$. However, I wanted to keep things simple. This can still be proven in a similar fashion.

SecondThread's video is great, it doesn't include this proof which I was looking for but I really recommend it.

Hope this helped! <3

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
3 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

m is generally a prime so its better to use the Fermat's little theorem to find the multiplicative modular inverse

  • »
    »
    3 месяца назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    They're both logarithmic time, not much difference in efficiency. I just prefer EEA because it's more general.