Doubt doubt doubt

a%n = b%n --> ye hame kyu chahiye ???

hello @parth_tyagi

.....a.......b....


a and b is the prefix sum right.

so b-a will give u sum of   subarray between them.
and we want this to be divisible  n hence we can write.

(b-a)%n=0
which is
b%n-a%n=0
b%n=a%n

(b-a)%n = (b%n) - (a%n) --> this is true if (b-a) >=0 ???

even if its negative, we can use it.

(b-a)%n=(b-a+n)%n (this is the property to make sure mod never become negative)

(b-a+n)%n on exapnding u will get the same thing.
also we are looking for zero
so even if (b-a) <=0
we can flip its sign (a-b)>=0 and then take its mod
(a-b)%n >=0
since we looking for == condition
a%n=b%n

(a-b)%m = [ (a%m) - (b%m) + m ] ----> a=3,b=9,m=5 , in this case LHS != RHS ???

the mod is on whole.

(3-9)%5 = (-6%5)= -1
now -1 represent that the differnce is a number that gives remainder -1.

5p-1 i,e the number is of type 5p-1
put p=0 u get -1 , put p=1 u will get 4 …
so all these numbers gives same remainder .
a remainder -1 is same as reaminder 4.

read about mod arithmetic

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.