Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll goodSub(ll a[], int n){
- ll aux[n], sum = 0;
- ll count = 0;
- for(int i = 0; i < n; i++){
- aux[i] = 0;
- }
- for(int i = 0; i < n; i++){
- sum += a[i];
- aux[sum % n]++;
- }
- for(int i = 0; i < n; i++){
- if(aux[i] > 1){
- count += (aux[i] * (aux[i] - 1)) / 2;
- }
- }
- count += aux[0];
- return count ;
- }
- int main(){
- int t;
- cin>>t;
- while(t--){
- ll n;
- cin>>n;
- long long a[n];
- for(int i = 0; i < n; i++)
- cin>>a[i];
- cout<<goodSub(a, n)<<endl;
- // cout<<subCount(a, n) <<endl;
- // cout<<"nest"<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment