#P9135. [THUPC 2023 初赛] 快速 LCM 变换
[THUPC 2023 初赛] 快速 LCM 变换
Problem Description
Little I is learning the Fast Least-Common-Multiple Transform (Fast Least-Common-Multiple Transform, FLT), so he wants to test you.
You are given a positive integer sequence of length . You need to perform the following operation exactly once:
- Choose integers such that . Append to the end of the sequence, and delete and from the sequence.
Note that there are possible operations in total, and each operation produces a sequence of length .
For all these sequences, you need to compute the least common multiple of all elements in the sequence, and output the sum of these values modulo .
Input Format
The first line contains a positive integer , representing the length of the sequence. The next line contains positive integers , describing the initial sequence.
Output Format
Output one integer on one line, representing the sum of the least common multiples of all resulting sequences modulo .
3
2 3 4
40
Hint
Sample Explanation 1
- When , the resulting sequence is , and the least common multiple is .
- When , the resulting sequence is , and the least common multiple is .
- When , the resulting sequence is , and the least common multiple is .
Therefore, the output is .
Subtasks
For all testdata, , and .
Source
From the 2023 Tsinghua University Programming Contest and Intercollegiate Invitational (THUPC2023) Preliminary.
Solutions and other resources are available at https://github.com/THUSAAC/THUPC2023-Pre.
Translated by ChatGPT 5