Source Code
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;


void prepareCom(vector<ll> &fC, vector<ll> &bC, vector<ll>mainArr){
	int len = mainArr.size();
	fC[0] = mainArr[0];
	bC[0] = mainArr[len-1];
	for(int i = 1, j = len-2; i < len && j >= 0; i++,j--){
		fC[i] = mainArr[i] + fC[i-1];
		bC[i] = mainArr[j] + bC[i-1];
	}
	return;
}

void prepareK(ll k, vector<ll> &sums, ll limit){
	int dis = k;
	while(k <= limit){
		sums.push_back(k);
		k += dis;
	}
	return;
}

vector<ll> prepareNewKs(ll corrent, vector<ll> sums){
	for(int i = 0; i < sums.size(); i++)
		sums[i] -= corrent;

	return sums;
}

void getAns(vector<ll> Ks, vector<ll> bC, int &ans, int I){
	I++;
	for(auto k : Ks){
		if(k < 1) continue;
		int l = 0, r = bC.size()-1-I, pivot;
		while(l <= r){
			pivot = (l + r)/2;
			if(bC[pivot] == k){
				ans++;
				break;
			}
			if(bC[pivot] > k)
				r = pivot-1;
			if(bC[pivot] < k)
				l = pivot+1;
		}
	}
	return;
}

void solve(){
	int n;
	ll k ans = 0;
	cin >> n >> k;

	vector<ll> mainArr(n);
	for(int i = 0; i < n; i++)
		cin >> mainArr[i];

	vector<ll> frontCom(n), backCom(n);
	prepareCom(frontCom, backCom, mainArr);

	vector<ll> sums;
	prepareK(k, sums, frontCom[frontCom.size()-1]);

	for(int i = 0; i < n; i++){
		
		vector<ll> newKs = prepareNewKs(frontCom[i], sums);
		getAns(newKs, backCom, ans, i);
	}

	cout << ans << endl;

	return;
}


int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}

	return 0;
}

/*
1 3 6 7 8 9
1 2 3 6 8 9

*/
Copy
Number of Ways MohaDarkness
GNU G++17
0 ms
0 KB
Compilation Error