0
点赞
收藏
分享

微信扫一扫

HDU 5776 sum


Problem Description


Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO


 



Input


1≤T≤10), which represents the number of test cases. 
For each test case, there are two lines:
1.The first line contains two positive integers n, m ( 1≤n≤100000,  1≤m≤5000).
2.The second line contains n positive integers x ( 1≤x≤100) according to the sequence.


 



Output


Output T lines, each line print a YES or NO.


 



Sample Input


2 3 3 1 2 3 5 7 6 6 6 6 6


 



Sample Output


YES NO




把前缀和对m取模,只要有相同的必然可以找到。


#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int T, n, m, x, y, s[N];

void solve()
{
rep(i, 0, m - 1)
{
if (s[i] > 1)
{
printf("YES\n");
return;
}
}
printf("NO\n");
}

int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d%d", &n, &m);
memset(s, y = 0, sizeof(s));
s[0] = 1;
rep(i, 1, n)
{
scanf("%d", &x);
s[(y += x) %= m]++;
}
solve();
}
return 0;
}


举报

相关推荐

0 条评论