Getting run time error while compiling the code
Sharad, can you pls tell the approach you have followed in your code, since i m not able to understand your code … on wht u have done.
I have used the pigeon hole concept as explained by bhaiya in the tutorial
I have created the prefix sum in the same array and then calculated the modulo of that array and finally calculating the result using nc2 formula
I have also commented out my code
I will see to your code and let u know…
Sharad, for large inputs, you code is not working correctly, the basic approach that you need to follow up is that, you need to create an array, initialise it to 0 and also, its first element to be 1, and then use the loop as ,
for(int i=0;i<n;i++)
{
sum=sum+ar[i];
sum=sum%n;
sum=(sum+n)%n;
prefixsum[sum]++;
}
Then you will calculate the value of ans as ,
long long int ans=0;
for(int i=0;i<n;i++)
{
long long int no=prefixsum[i];
ans=ans+(no*(no-1))/2;
}
This is the basic approach you need to follow up so as to get the desired result for your code…