http://blog.csdn.net/queuelovestack/article/details/52075208#comments
别人写的太好了,借鉴借鉴
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 100005;
const int M = 5005;
const int inf = 1000000007;
const int mod = 1000000007;
int a[N];///前缀和(预处理后的)
int v[N];
int main()
{
int T,m,n,x,key;
cin>>T;
while(T--){
memset(a,0,sizeof(a));
memset(v,0,sizeof(v));///
cin>>n>>m;
a[0]=0;
for(int i=1;i<=n;i++){
cin>>x;
a[i]=(a[i-1]+x)%m;
}
key=0;
for(int i=0;i<=n;i++)//从0开始是因为前缀和取模为0出现一次就可认定区间元素之和是m的倍数
{
if( v[a[i]]==1 )
{
cout<<"YES"<<endl;
key=1;
break;
}
v[a[i]]=1;
}
if(key==0)cout<<"NO"<<endl;
}
return 0;
}