Complement: Best Coder #85 1001 Sum (prefix and)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.