#GL0000302. Ghép số thành bội (Concatenated Multiples)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ghép số thành bội (Concatenated Multiples)
Concatenated Multiples
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of positive integers and an integer .
The concatenation of and is obtained by writing the full decimal representation of immediately after that of . For example, concatenating and produces .
Count the ordered pairs of positions with and for which concatenating before gives an integer divisible by .
Different positions are counted separately even if their values are equal; and are different pairs.
Input
The first line contains two integers and .
The second line contains exactly integers in array order.
Output
Print one integer: the number of valid ordered pairs of positions.
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Example 1
Input
6 11
45 1 10 12 11 7
Output
7
Explanation
The seven valid position pairs are . They produce , all divisible by .
Example 2
Input
4 2
2 78 4 10
Output
12
Explanation
Every ends with an even digit, so every concatenation is divisible by . There are ordered pairs with different positions.
Example 3
Input
5 2
3 7 19 3 3
Output
0
Explanation
Every value ends in an odd digit. A concatenation ends with the last digit of , so none is divisible by .