Source Code
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <math.h>
#include <vector>
#include <set>
#include <map>
using namespace std;
long long a[100001];
int main() {
	int t;
	long long ans, sum, x, n, k;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		ans = sum = x = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			sum += a[i];
		}
		if (sum % k == 0)ans += (n - 1);
		for (int i = 1; i < n - 1; i++) {
			x += a[i];
			if ((sum - a[i]) % k == 0)ans++;
			if (x != a[i] && (sum - x ) % k == 0)ans++;
		}
		cout << ans << endl;
	}
	return 0;
}






Copy
Number of Ways Sarah
GNU G++17
37 ms
312 KB
Wrong Answer