Modulo of Division of Two Numbers
Yes, but it's different:
(a - b) mod p = ((a mod p - b mod p) + p) mod p
(a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
Where b^(-1) mod p
is the modular inverse of b
mod p
. For p = prime
, b^(-1) mod p = b^(p - 2) mod p
.
Edit:
(N*(N^2+5)/6)%P
You don't need any modular inverses from this. Just simplify the fraction: N or N^2+5
will be divisible by 2
and 3
. So divide them and then you have (a*b) mod P
.
Vlad's answer is correct:
(a - b) mod p = ((a mod p - b mod p) + p) mod p
(a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
These and some other operations are outlined here in the Equivalencies section.
Just want to let you know that this will work not only for prime number p
. The first one will work for any p
. The second one will work for any p
, where b^(-1)
or modular inverse is defined.
The modular inverse can be calculated with extended Euclidian algorithm