To a sub-segment k is divisible by only two of the prefix and the% k meaning the lower phase was reduced to 0
k is small, can start recording a bucket% k value, for the same value as long as the two can be picked from the inside, so that the contribution of each value of the answer is $ C ^ {2} _ {b [i]} $
Note that the original can be included in a separate answer 0, and finally add about
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
usingnamespace std;
constint maxn=50009;
int n,t,b[1000009];
ll sum[maxn],x,ans,k;
int main(){
scanf("%d",&t);
while(t--){
scanf("%lld%d",&k,&n);ans=0;
memset(sum,0,sizeof(sum));
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
scanf("%lld",&x),sum[i]=(sum[i-1]+x)%k,b[sum[i]]++;
for(int i=0;i<=k-1;i++)ans+=b[i]*(b[i]-1)/2;
printf("%lld\n",ans+b[0]);
}
}