Guest User

Untitled

a guest
Dec 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. ll goodSub(ll a[], int n){
  6.     ll aux[n], sum = 0;
  7.     ll count = 0;
  8.    
  9.     for(int i = 0; i < n; i++){
  10.         aux[i] = 0;
  11.     }
  12.     for(int i = 0; i < n; i++){
  13.         sum += a[i];
  14.         aux[sum % n]++;
  15.     }
  16.    
  17.     for(int i = 0; i < n; i++){
  18.        
  19.         if(aux[i] > 1){
  20.             count += (aux[i] * (aux[i] - 1)) / 2;
  21.         }
  22.     }
  23.     count += aux[0];
  24.     return count ;
  25. }
  26.  
  27.  
  28. int main(){
  29.    
  30.     int t;
  31.     cin>>t;
  32.     while(t--){
  33.         ll n;
  34.         cin>>n;
  35.         long long a[n];
  36.         for(int i = 0; i < n; i++)
  37.             cin>>a[i];
  38.         cout<<goodSub(a, n)<<endl;
  39.        // cout<<subCount(a, n) <<endl;
  40.     //  cout<<"nest"<<endl;
  41.     }
  42.    
  43.     return 0;
  44. }
Add Comment
Please, Sign In to add comment