#P8712. [蓝桥杯 2020 省 B1] 整数拼接

[蓝桥杯 2020 省 B1] 整数拼接

Problem Description

You are given an array A1,A2,,AnA_1, A_2, \cdots, A_n of length nn. You may choose two numbers AiA_i and AjA_j (iji \neq j), then concatenate AiA_i and AjA_j in order to form a new integer. For example, 12 and 345 can be concatenated into 12345 or 34512. Note that swapping the order of AiA_i and AjA_j is always considered as 22 different ways of concatenation, even when Ai=AjA_i = A_j.

Please compute how many concatenations result in an integer that is a multiple of KK.

Input Format

The first line contains 22 integers nn and KK.

The second line contains nn integers A1,A2,,AnA_1, A_2, \cdots, A_n.

Output Format

Output one integer representing the answer.

4 2
1 2 3 4
6

Hint

For all test cases, 1n1051 \le n \le 10^5, 1k1051 \le k \le 10^5, and 1Ai1091 \le A_i \le 10^9.

Lanqiao Cup 2020, First Round Provincial Contest, Group B, Problem I.

Translated by ChatGPT 5