#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 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 seconds will make a sound at the rd second, the th second, the th second, and so on.
Xiaoming wants to know: within the first seconds (i.e., from the st second to the th second, including the th second), how many moments are there when exactly instruments make sounds at the same time?
Input Format
The first line contains three integers , representing the number of instruments, the observation duration, and the number of instruments that make sounds simultaneously.
The second line contains integers , representing the beat period of each instrument (unit: seconds).
Output Format
Output one line with one integer, representing the number of moments when exactly 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 , , and seconds. Within the first 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 instruments make sounds simultaneously are , for a total of moments.
Sample Explanation 2
The instrument periods are , , , and seconds. Within the first seconds, the moments when exactly 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 , , and is , so at times these three instruments will make sounds at the same time. Instrument (period ) does not make a sound at these times, so there are exactly instruments.
Constraints and Notes for Test Cases
For of the test cases, , .
For of the test cases, , .
For all test cases, , , , .
Translated by ChatGPT 5