#P16284. [蓝桥杯 2026 省 Python A 组] 音乐节拍器

[蓝桥杯 2026 省 Python A 组] 音乐节拍器

Problem Description

Xiaoming is learning music. He finds that playing different instruments requires matching different beats. Now there are NN kinds of instruments, and each instrument has its own “beat period” (in seconds).

In music performance, if a certain moment is exactly an integer multiple of an instrument’s beat period, then this instrument will make a sound at that moment. For example, an instrument with a beat period of 33 seconds will make a sound at the 33rd second, the 66th second, the 99th second, and so on.

Xiaoming wants to know: within the first TT seconds (i.e., from the 11st second to the TTth second, including the TTth second), how many moments are there when exactly KK instruments make sounds at the same time?

Input Format

The first line contains three integers N,T,KN, T, K, representing the number of instruments, the observation duration, and the number of instruments that make sounds simultaneously.

The second line contains NN integers p1,p2,,pNp_1, p_2, \dots, p_N, representing the beat period of each instrument (unit: seconds).

Output Format

Output one line with one integer, representing the number of moments when exactly KK instruments make sounds simultaneously.

3 12 2
2 3 4
3
4 20 3
2 3 5 6
3
5 100 1
7 11 13 17 19
36

Hint

Sample Explanation 1

The instrument periods are 22, 33, and 44 seconds. Within the first 1212 seconds, the sounding situation at each moment is shown in the table below:

Time Instrument 1 (period 2) Instrument 2 (period 3) Instrument 3 (period 4) Number of sounding instruments
1 - - - 0
2 1
3 -
4 - 2
5 - - 0
6 2
7 - - 0
8 2
9 - - 1
10 -
11 - 0
12 3

In the table, “✓” means the instrument makes a sound at that moment, and “-” means it does not.

The moments when exactly 22 instruments make sounds simultaneously are t=4,6,8t = 4, 6, 8, for a total of 33 moments.

Sample Explanation 2

The instrument periods are 22, 33, 55, and 66 seconds. Within the first 2020 seconds, the moments when exactly 33 instruments make sounds simultaneously are shown in the table below:

Time Instrument 1 (period 2) Instrument 2 (period 3) Instrument 3 (period 5) Instrument 4 (period 6) Number of sounding instruments
6 - 3
12
18

Explanation: the least common multiple of instruments 11, 22, and 44 is 66, so at times 6,12,186, 12, 18 these three instruments will make sounds at the same time. Instrument 33 (period 55) does not make a sound at these times, so there are exactly 33 instruments.

Constraints and Notes for Test Cases

For 30%30\% of the test cases, N5N \leq 5, T100T \leq 100.

For 60%60\% of the test cases, N10N \leq 10, T1000T \leq 1000.

For all test cases, 1N201 \leq N \leq 20, 1T100001 \leq T \leq 10000, 1KN1 \leq K \leq N, 1pi1001 \leq p_i \leq 100.

Translated by ChatGPT 5