-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgood_array_2.cpp
More file actions
53 lines (44 loc) · 761 Bytes
/
Copy pathgood_array_2.cpp
File metadata and controls
53 lines (44 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Source: Hackerblocks
*/
#include <iostream>
using namespace std;
int goodArray(int *arr, int n )
{
int sum=0;
int count=0;
int cSum[n]={arr[0]};
for(int i=1;i<n;i++)
{
cSum[i]=cSum[i-1]+arr[i];
}
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
sum=cSum[j]-cSum[i]+arr[i];
if(sum%n==0)
{
count++;
}
}
}
return count;
}
int main() {
int t;
cin>>t;
while(t)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<goodArray(arr,n)<<endl;
t--;
}
return 0;
}