Source Code
#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t > 0)
	{
		unsigned long long n, k;
		cin >> n >> k;
		unsigned long long* arr = new unsigned long long[n];
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
			sum += arr[i];
		}
		unsigned long long int count = 0;
		if (sum % k == 0)
			count += n - 1;
		for (int i = 1; i < n - 1; i++)
		{
			unsigned long long otherSum = sum;
			for (int j = i; j < n - 1; j++)
			{
				otherSum -= arr[j];
				if (otherSum % k == 0)
					count++;
			}
		}
		cout << count << endl;
		t--;
	}
}
Copy
Number of Ways Heromnxpw0
GNU G++17
83 ms
1.9 MB
Wrong Answer