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
*/
+38
View File
@@ -0,0 +1,38 @@
# P8712 [蓝桥杯 2020 省 B1] 整数拼接
## 题目描述
给定一个长度为 $n$ 的数组 $A_1,A_2,\cdots,A_n$。你可以从中选出两个数 $A_i$ 和 $A_j$($i\neq j$),然后将 $A_i$ 和 $A_j$ 一前一后拼成一个新的整数。例如 `12` 和 `345` 可以拼成 `12345` 或 `34512`。注意交换 $A_i$ 和 $A_j$ 的顺序总是被视为 $2$ 种拼法,即便是 $A_i=A_j$ 时。
请你计算有多少种拼法满足拼出的整数是 $K$ 的倍数。
## 输入格式
第一行包含 $2$ 个整数 $n$ 和 $K$。
第二行包含 $n$ 个整数 $A_1,A_2,\cdots,A_n$。
## 输出格式
一个整数代表答案。
## 输入输出样例 #1
### 输入 #1
```
4 2
1 2 3 4
```
### 输出 #1
```
6
```
## 说明/提示
对于所有评测用例,$1\le n\le10^5$,$1\le k\le10^5$,$1\le A_i\le10^9$。
蓝桥杯 2020 第一轮省赛 B 组 I 题。