#P9135. [THUPC 2023 初赛] 快速 LCM 变换

    ID: 10207 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2023数论O2优化快速傅里叶变换 FFTTHUPC

[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 r1,r2,,rnr_1, r_2, \cdots, r_n of length nn. You need to perform the following operation exactly once:

  • Choose integers i,ji, j such that 1i<jn1 \le i < j \le n. Append (ri+rj)(r_i + r_j) to the end of the sequence, and delete rir_i and rjr_j from the sequence.

Note that there are n(n1)2\frac{n(n-1)}{2} possible operations in total, and each operation produces a sequence of length n1n-1.

For all these n(n1)2\frac{n(n-1)}{2} sequences, you need to compute the least common multiple of all elements in the sequence, and output the sum of these values modulo 998244353998244353.

Input Format

The first line contains a positive integer nn, representing the length of the sequence. The next line contains nn positive integers r1,r2,,rnr_1, r_2, \cdots, r_n, 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 998244353998244353.

3
2 3 4

40

Hint

Sample Explanation 1

  • When i=1,j=2i = 1, j = 2, the resulting sequence is {4,5}\{4, 5\}, and the least common multiple is 2020.
  • When i=1,j=3i = 1, j = 3, the resulting sequence is {3,6}\{3, 6\}, and the least common multiple is 66.
  • When i=2,j=3i = 2, j = 3, the resulting sequence is {2,7}\{2, 7\}, and the least common multiple is 1414.

Therefore, the output is 20+6+14=4020 + 6 + 14 = 40.

Subtasks

For all testdata, 2n5×1052 \le n \le 5 \times 10^5, and 1r1,r2,,rn1061 \le r_1, r_2, \cdots, r_n \le 10^6.

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