new file: P8712.cpp
Check cpp / md pair / Check md headers (push) Failing after 0s

This commit is contained in:
hanyixuanten committed 2026-10-21 13:20:41 +00:00
1 parent 6f8224592e
commit fc217aeee6
2 files changed
+72

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, k;
int a[100005];
int mod[100005][11];
int ks[100005][11];
signed main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
mod[i][0] = a[i] % k;
ks[mod[i][0]][0]++;
for (int j = 1; j <= 10; ++j) {
mod[i][j] = (mod[i][j - 1] * 10) % k;
ks[mod[i][j]][j]++;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) { // 作为底部
int len, now = a[i];
for (len = 0; now; len++, now /= 10)
;
int want = (k - mod[i][0]) % k;
ans += ks[want][len];
if (mod[i][len] == want)
ans--;
}
printf("%lld\n", ans);
return 0;
}
/*
计算 *10^i mod k
*/