fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10.  
  11. int c;
  12. cin >> c;
  13.  
  14. while(c--){
  15. int n, d;
  16. cin >> d >> n;
  17. vector<long long> cnt(d);
  18. int sum = 0;
  19. long long answer = 0;
  20. for(int i = 0; i < n; i++){
  21. int x;
  22. cin >> x;
  23. sum = (sum + x) % d;
  24. answer += cnt[sum]++;
  25. }
  26. answer += cnt[0];
  27. cout << answer << "\n";
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5388KB
stdin
2
7 3
1 2 3
4 8
2 1 2 1 1 2 1 2
stdout
0
6