Source Code
#include<iostream>
#include<algorithm>
#include<deque>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#define OmarNasr {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
using namespace std;
long long p[200002], s[200002];
int main()
{
	long long t, n, k;
	cin >> t;

	while (t--)
	{
		long long mx = 0;

		cin >> n >> k;
		for (int i = 1; i <= n; i++)
		{
			cin >> p[i];
			p[i] += p[i - 1];
		}
		int c = 1;
		s[n] = p[n];
		for (int i = n - 1; i >= 1; i--)
			s[c++] = p[n] - p[i];
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= (n-i); j++) {
				if (1ll*i + j <= n && (p[i] + s[j]) % k == 0) {
					mx++;
				}
			}
		}
		cout << mx << "\n";
	}
}
Copy
Number of Ways OmarNasr
GNU G++17
2096 ms
448 KB
Time Limit Exceeded