My code is showing run time error in 2nd test case while submitting . please help . code link : https://ide.codingblocks.com/s/101133
Algo++ : Divisible subarrays
Hello,
The run time error is coming because you are not considering the case that the sum can also be negative.
Thus, to resolve this problem you have to take modulo twice.
I have modified your code:
for(long long int i=0;i<n;i++)
{
sum[i]=sum[i]%n;
sum[i]=(sum[i]+n)%n; //second modulo
r[sum[i]]++;
}
Hope, this would help.
Give a like, if you are satisfied.