Sumaccepts:640submissions:1744Time limit:2000/1000 MS (java/others)Memory limit:131072/131072 K (java/others)Problem Description
Given a sequence, you ' re asked whether there exists a consecutive subsequence whose sum are divisible by M. output YES, oth Erwise Output NO
Input
The first line of the input have an integer T (1≤t≤101 \leq T \leq 101≤T≤10), which represents the number of test cases. For each test case, there is lines:1.the first line contains, positive integers n, m (1≤n≤1000001 \leq N \leq 1000001≤N≤100000, 1≤m≤50001 \leq m \leq1≤m≤5000). 2.The second line contains n positive integers x (1≤x≤1001 \leq x \leq1≤x≤100) According to the sequence.
Output
Output T lines, each line print a YES or NO.
Sample Input
23 31 2 35 76 6 6 6 6
Sample Output
YESNO
/* For the first time to play BC, as a big water B, the waters out together, already very happy * *
/* Use prefix and to iterate through each successive sequence of the and */
#include <iostream>#include<stdio.h>#include<string.h>#defineN 100010using namespacestd;Long LongA[n],sum[n];intMain () {//freopen ("In.txt", "R", stdin); intT; intn,m; scanf ("%d",&t); while(t--) {memset (sum,0,sizeofsum); Memset (A,0,sizeofa); scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); Sum[i]=sum[i-1]+A[i]; } intflag=1; for(intI=1; i<=n;i++) { for(intj=i;j<=n;j++) { if((sum[j]-sum[i-1])%m==0) {puts ("YES"); Flag=0; Break; } } if(!flag) Break; } if(flag) printf ("no\n"); } return 0;} Close Bestcoder Contest System2.0Copyright© the- .HDU ACM
Complement: Best Coder #85 1001 Sum (prefix and)