Divisible subarrays (Challenges Number Theory)

Hey
So after watching the concept of divisble arrays i tried to code it own my own before watching the actual code video

But only two test cases are running fine , for two exclamation mark is coming and for one wrong answer

hello @nischay1111
a) use long long in place of int.
b) use modular arithmetic while permforming addition
i,e (a+b)%mod =(a%mod+b%mod)%mod
c) dont use factorical . it might cause overflow.
nc2=n*(n-1)/2 so use this formula in place of factorial.

hey i made the changes suggested but stll showing exclamation for three test cases


here is the link to the new changed code

finally modified code according to the video
still two test cases not passing

@nischay1111

image

replace this line with.
sum=(sum+a[i])%n

Thanks
though i was able to solve the problem with your help
But when i was writing in line 22
sum+=a[i]
then in the next line i was also doing
sum=(sum+n)%n

so how is changing line 22 with sum=(sum+a[i])%n making a difference ?

sum+a[i] might oveflow so was taking % n to avoid it.

refer this article-> https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/tutorial/

okay
thanks a lot for the help

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.