In this question , why bhaiya is doing pre[0]=1 initially, i’m not able to understand this concept.
DIVISIBLE SUBARRAYS
hello @CODER_JATIN
an empty subarry array will have 0 modulo.
thats why we r initialsing pre[0] with 1.
this 1 is to consider that empty array
but why we are taking empty subarray in cinsideration?
consideration* . . . . .
consider this case->
n=3
1 2 3
subarray whose mod is 0-> (1,2) (3), (1,2,3) right?
but the prefix formula we are using will count only 2 subarrays.
i.e it will count only (1,2) , (3)
so to avoid this we are initialsing it with 1.
okay okay if arr[]=1,2,3 then prefix sum formula will count subarrays (1,2) and (1,2,3) but it will not count only (3) right??
oh so sorry i made one mistake,
the prefix method will only count ( 3 ) subarray .
how ?
total 2 times our prefix mod sum will be 0 right?
so pre[0]=2 right?
now from formula -> pre[0] * (pre[0]-1)/2 -> 1 which is clearly wrong ( this 1 is for subarray [3] other subarrays ie [1,2] , [1,2,3] are lost).
thats why we initialised pre[0] with 1 .
so after iteration we will have pre[0]=3 and now if we will aplly pre[0]*(pre[0]-1)/2 -> 3 which is now correct
to matlab final conclusion yeh hai ki jo hmaara null subarray hai uska modulo 0 hoga hamesha?
Correct… . . . . . . . . .
Use long long for ur finaarray
When i’m using long long int for the final arrya, it is showing dumped core
pls share ur updated code using cb ide
bhaiya, have you saw my quesyion?
a) use long long
b) dont create array of fixed size, always create array of given size n (as this way ,ur program will utilise only required amount of memory)
ur updated code->
Okay bhaiiya , thank you 
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.