luogu#P5518. [MtOI2019] 幽灵乐团 / 莫比乌斯反演基础练习题

    ID: 4107 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019洛谷原创Special JudgeO2优化莫比乌斯反演整除分块

[MtOI2019] 幽灵乐团 / 莫比乌斯反演基础练习题

Background

In Hakugyokurou, the concert in the Netherworld has begun.

Lunasa, Lyrica, and Merlin are performing.

Problem Description

Kochiya Sanae really likes the performance of the Ghost Band, and she wants to score their performance.

Since the Ghost Band has 33 members, we can use three positive integers A,B,CA,B,C to represent the score of the band’s performance. Their performance score can be written as

$$\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)^{f(type)}$$

Because the music sounds different in different parts, typetype changes within {0,1,2}\{0,1,2\}, where:

$$\begin{aligned} f(0)&=1 \cr f(1)&=i \times j \times k \cr f(2)&=\gcd(i,j,k) \end{aligned}$$

Because the band’s songs are so good that the score becomes very large, the score should be taken modulo a given positive integer pp.

Since there are many songs to perform, Sanae gives TT queries.

Input Format

The first line contains two positive integers TT and pp, as described above.

The next TT lines each contain three positive integers A,B,CA,B,C, representing one query.

Output Format

Output TT lines. Each line contains three positive integers, representing the value of the given expression when type=0/1/2type=0/1/2, respectively.

3 998244853
1 1 1
2 2 2
3 3 3

1 1 1
16 4096 16
180292630 873575259 180292630

Hint

Constraints and Notes

For 10%10\% of the testdata:

1A,B,C501\leq A,B,C\leq 50

For 20%20\% of the testdata:

1A,B,C1001\leq A,B,C\leq 100

Another 10%10\% of the testdata:

1A,B,C100     A=B=C1\leq A,B,C\leq 100\ \ \ \ \ A=B=C

For 60%60\% of the testdata:

1A,B,C1031\leq A,B,C\leq 10^3

For 100%100\% of the testdata:

$$1\leq A,B,C\leq 10^5 \ \ \ \ 10^7 \leq p \leq 1.05\times 10^9\ \ \ \ p\in \{ prime\} \ \ \ \ T =70$$

Sanae is very kind. Even if you do not know all the correct answers, she will still give you some points.

  • If your first column is correct, she will give you 20%20\% of the score for this test point.
  • If your second column is correct, she will give you 40%40\% of the score for this test point.
  • If your third column is correct, she will give you 40%40\% of the score for this test point.

So even if you do not know what the answers are, please output an integer in [0,231)[0,2^{31}) for the parts you do not know, otherwise it may cause unpredictable errors.

Source

Lost House 2019 League (MtOI2019) T5.

Problem setter: CYJian.

Translated by ChatGPT 5