Test instructions: Given the number of N, and M, ask you if there is a continuous number and a multiple of M.
Analysis: Consider the prefix and, if there are two prefixes and modulo m equal, then is equal, must pay attention, if modulo is 0, is true, do not forget, I did not remember ....
The code is as follows:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype>using namespace std; typedef long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e5 + 5;const int D R[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && ; R < n && C >= 0 && C < m;} int Vis[maxn];int Main () {//Ios::sync_with_stdio (FALSE); int T, q; Cin >> T; while (t--) {scanf ("%d%d", &n, &m); LL sum = 0; memset (Vis, 0, sizeof (VIS)); bool OK = false; Vis[0] = 1; for (int i = 0; i < n; ++i) {scanf ("%d", &q); sum + = q; if (vis[sum%M]) ok = true; VIS[SUM%M] = 1; } printf ("%s\n", OK?) "YES": "NO"); } return 0;}
HDU 5776 sum (prefix and)