Divisible subarrays - Run error

Encountering run error in some test cases.

#include
#define ll long long
using namespace std;

ll fact(ll n)
{
ll res = 1;
for (ll i = 2; i <= n; i++)
res = res * i;
return res;
}

ll nCr(ll n, ll r)
{
return fact(n) / (fact® * fact(n - r));
}

ll answer(ll a[], ll n)
{
ll s[n+1] = {0};
ll freq[n] = {0};
ll ans = 0;
for(ll i=0; i<n; i++)
{
s[i+1] = s[i] + a[i];
s[i+1] %= n;
}

for(ll i=0; i<n+1; i++)
{
	freq[s[i]]++;
}

for(ll i=0; i<n; i++)
{
	if(freq[i] >= 2){
		ans = ans + nCr(freq[i], 2);
	}
}

return ans;

}

int main() {
ll t;
cin>>t;

while(t--)
{
	ll n;
	cin>>n;

	ll a[n];
	for(ll i=0; i<n; i++)
	{
		cin>>a[i];
	}

	cout<<answer(a,n)<<endl;

}
return 0;

}

@abhishekchoudhary
abhishek dont use ncr function because overflow issue will occur due to this.
nc2 = n*(n-1)/2 so use this formula in place of ncr

@abhishekchoudhary
also check this video tutorial by prateek bhaiya

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.