title: Find numbers of subarray of an array whose sum is divided by given number
body: <p>I got stuck in one algorithm question. Please suggest me some efficient algorithm for the below problem.</p>
  
  <p><strong>Question is</strong></p>
  
  <p>Find numbers of subarrays whose sum is divisible by given number.</p>
  
  <p><strong>My work</strong></p>
  
  <p>I made one algorithm, whose complexity is O(N^2), here, N = size of an array.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  using namespace std;
  
   main() {
      int N;
      int P;
      int T;
      int val;
      long long int count = 0;
      long long int answer = 0;
      scanf("%d", &amp;T);
      //T = 20;
  
      for(int k = 1; k &lt;= T; k++) {
          scanf("%d", &amp;N);
          scanf("%d", &amp;P);
          count = 0;
          answer = 0;
          for(int i = 0; i &lt; N; i++) {
              scanf("%d", &amp;val);
              count += val;
              workingArray[i] = count;
          }
  
          for(int length = 1; length &lt;= N; length++) {
              for(int start = 0; start &lt;= (N-length); start++) {
                  if( start == 0 ) {
                      if(workingArray[start+length-1]%P == 0) answer++;
                  }
                  else if( (workingArray[start+length-1] - workingArray[start-1])%P == 0) answer++;
              }
          }
  
          printf("Case #%d\n%lld\n", k, answer);
      }
      return 0;
   }
  </code></pre>