-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc164_d.cpp
48 lines (38 loc) · 800 Bytes
/
abc164_d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
const int mod = 2019;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
vector<int> ds(n);
for (int i =0 ; i < n; i++) {
ds[i] = s[i] - '0';
}
vector<int> cong(n);
vector<int> hist(mod);
int cur = 0;
for (int i = n - 1, p10 = 1; i >= 0; i--, p10 = (p10*10) % mod) {
cur = (cur + ds[i] * p10) % mod;
cong[i] = cur;
hist[cur]++;
}
int ans = 0;
cur = 0;
ans += hist[0];
for (int i = n - 1, p10 = 202; i >= 2; i--, p10 = (p10*202) % mod) {
hist[cong[i]]--;
ans += hist[cong[i]];
/*
for (int m = 0; m < mod; m++) {
int x = (m - cong[i] + mod) % mod;
x = (x*p10) % mod;
if (x == 0) ans += hist[x];
}
*/
}
cout << ans << '\n';
}
// AC, math, number theory