#P7890. 「MCOI-06」Lost Desire

    ID: 7995 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2021Special JudgeO2优化哈希 hashing素数判断,质数,筛法最大公约数 gcd莫比乌斯反演组合数学随机化洛谷月赛

「MCOI-06」Lost Desire

Background

頰滴る 紅い涙

不安定な視界の中

差し出した手を取れたら

あぁ…そんな世界を夢みた


哭いて…

激しく 燃やした 黒い感情

届かぬ この手に

Cry 闇の中で

最果てから 光へ手を翳して

揺らいだ想いさえも 闇の奥底へ堕ちてく

Netease Cloud Music trial listening link for this song

Problem Description

Let positive integers n,mn, m be coprime, and let kk be an integer. Define the function F(n,m,k)F(n, m, k) as follows: among the set of positive integers less than m+n\displaystyle m+n, {1,2,,m+n1}\{1, 2, \cdots, m + n - 1\}, consider all mm-element subsets SS that satisfy xSxk(modn)\displaystyle\sum_{x \in S} x \equiv k \pmod n. Then F(n,m,k)F(n, m, k) is the number of such subsets SS.

Now given positive integers N,M,KN, M, K, compute the product of all F(i,j,x)F(i, j, x) such that 1iN1 \le i \le N, 1jM1 \le j \le M, 1xK1 \le x \le K, and ii and jj are coprime.

Since the result is very large, you only need to output the value modulo a given prime pp.

Also, please pay attention to the impact of constant factors when implementing your program.

Input Format

This problem has multiple test cases. Each test point contains a total of TT test cases.

The first line contains two positive integers T,pT, p.

The next TT lines each contain three positive integers N,M,KN, M, K, separated by spaces.

Output Format

For each test case, output one line with one integer, representing the required value (modulo pp).

3 1926195307
2 3 3
3 3 3
5 6 1
8
64
363031200

Hint

This problem uses bundled tests, divided into 55 subtasks.

  • For Subtask 1 (Tutorial):
    • T=1T=1.
    • 1N,M,K61 \leq N, M, K \leq 6.
    • p=109+7p=10^9+7.
  • For Subtask 2 (PST 4.0):
    • T=1T=1.
    • 1N,M,K2001 \leq N, M, K \leq 200.
    • p=109+7p=10^9+7.
  • For Subtask 3 (PRS 7.5):
    • T=100T=100.
    • 1N,M,K10001 \leq N, M, K \leq 1000.
    • p=109+7p=10^9+7.
  • For Subtask 4 (FTR 9.8):
    • T=103T=10^3.
    • 1N,M,K1051 \leq N, M, K \leq 10^5.
    • 109p2×10910^9 \le p \le 2 \times 10^9.
  • For Subtask 5 (BYD 11.0):
    • T=9999T=9999.
    • 1N,M,K5×1051 \leq N, M, K \le 5 \times 10^5.
    • 109p2×10910^9 \le p \le 2 \times 10^9.

The scores for Subtasks 151 \sim 5 are 5,7,11,17,605, 7, 11, 17, 60, respectively.

In particular, suppose that in one test point the first xx queries are correct; then you get $\left\lfloor100\times\sqrt\dfrac{x}{T}\right\rfloor\%$ of the score of that test point. Your score for any Subtask is the minimum score among all test points in that Subtask.

In particular, any TLE gets 00 points. (There is no need to fill in the answers for test points that are not solved within the time limit; doing so may cause strange errors.)

Reminder again: please pay attention to the impact of constant factors when implementing your program.


Idea: Powerless Std&Data: w33z (Data was corrected on 2021.10.05).

Subtask 4 was added by Prean, and Subtask 5 by w33z.

This problem was added on 2021.10.01. Thanks for their help.

2021.10.01 - 2021.12.07: 68 days, 1st kill (Leasier).

2021.10.01 - 2022.01.21: 113 days, 2nd kill (wkywkywkywky).

2021.10.01 - 2022.02.26: 149 days, 3rd kill (NaNH2).

Translated by ChatGPT 5