#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int t;
cin>>t;
while(t–){
long long int n;
cin>>n;
long long int arr[n];
vector dp;
dp.push_back(0);
long long int j=1;
long long int sum=0;
map<long long int,long long int> m;
m[0]=1;
for(long long int i=0;i<n;i++)
{
cin>>arr[i];
sum=sum+arr[i];
dp.push_back(sum%n);
m[sum%n]+=1;
}
sum=0;
for(long long int i=0;i<=n;i++)
{
if(m[i]>=2)
{
sum=sum+(m[i]*(m[i]-1)/2);
}
}
cout<<sum<<endl;
}
return 0;
}
Code for divisible subarrays not getting accepted
@praritv1
As the numbers could be negative as well. Therefore sum%n could also give negative values therefore to avoid that you add n and again take mod.
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.