DIvisible Subarray is giving run time error


i have modified your code see it
you need not to use factorial function as every time you have to calculate nC2 which is equal to n*n(n-1)/2;
second thing not write arr[n] as value of n is not known at compile time it will be given at run time
for(int i=0;i<n;i++){
modarr[i+1] = ((arr[i]%n)+n)%n;
i have done this because arr[i]%n can be negative i
n this case it create problem so i do this to make it possitive otherwise it will create problem while writing freq[modarr[i]]++;
and give run-error

and also constraints are big you have to use long long int
after doing these changes you code will accepted

if you understand then hit a like

I can’t understand why we can’t take size of array as n ans modarr as n+1

it is for negative nos