In this video sir write what is written on image and than write code for it line 18 of program. I want to understand the logic behind them and also the use of memset function.https://ide.codingblocks.com/s/486867
Divisible Subarrays
hello @sarthak_singhal
thats a mod property , it is done to avoid negative value resultant.
(a+b)=(a+b+n)%n is done to ensure that resutant remain positive
we wanr it positive becuase we are using these value as array and indices and we cant give negative value as index in array
but suppose I get -5+3 = -2 in my cumulative sum and than -2%5 = -2 but here we do -2+5 = 3 -> 3%5=3 so this 3 will be included with the 3 that is remainder of other numbers but this 3’s original remainder was -2 will it not effect the answer ??
but suppose I get -5+3 = -2 in my cumulative sum and than -2%5 = -2 but here we do -2+5 = 3 -> 3%5=3 and it also violates the property
no it will not affect the answer basically both are indicating same thing
if some one is saying on diving a number by 5 u get -2 then it is same as dividing a number and getting remainder as 3.
N= 5x-2 (N : number that gives -2 as remainder)
now add and subtract 5 from right side
N= 5x-2+ 5-5
N= 5*(x-1) + 3 (N : number that gives 3 as remainder )
see both are same
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.