Often while doing competitive coding challenges we come across modulo problems. Many of the times it becomes too tedious to get away with them. But if we apply some of the basic properties of modulus it becomes as easy as pie.

Some of the most used properties of modulo are :-

1) (a*b)%m=(a%m)*(b%m)%m.

2) (a+b)%m= {(a%m)+(b%m)}%m.

these properties often become handy when we have to deal with large integers in C or C++;

There is one more trick which comes out to be handy when we have to deal with division modulo because the conventional method of calculating modulo inverse is very tough and lengthy. First understand this line:-

**a = b mod m **; This statement means same as a%m=b;

Now if we have to calulate the value of b for x/y we can do it like this:-

x/y = ? mod m

or x = (? * y) mod m*y; A property which modulo follows. Forget proof, just remember the expression. It means that just calculate

x % (m*y) and you will get the value of (? * y). Now just divide it by Y and you will get the value of ?.

</Keep Coding>

### Like this:

Like Loading...

*Related*

dude good job . Could have done a bit more research but anyway