I am learning the usage of mod in programming to overcome the overflows.
I was able to deduce the following relation ships:
for example if I want to perform addition between $a$ and $b$ and the result must be modulo to M then i can perform the above operation as : $((a\%M)+(b\%M))\%M$ similarly for multiplication: $((a\%M)*(b\%M))\%M$
Right now I was stuck up with division can any body tell me how to perform the division between $a$ and $b$ & modulo the result by $M$.
Please suggest me some ways to get the solution.
What about the case if $M$ is prime and what about the case if $M$ is non-prime.