#P12011. 【MX-X10-T7】[LSOT-4] 春开,意遥遥。

    ID: 11667 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学原根数论大步小步算法 BSGS梦熊比赛

【MX-X10-T7】[LSOT-4] 春开,意遥遥。

Description

Define the multiplication of ordered pairs as:

$$(x,y) \times (a,b) = (x \times b + y \times a,\ x \times a + y \times b).$$

Since this multiplication satisfies the associative law (verification is left to the reader), we can define the exponentiation of ordered pairs: for an ordered pair aa and a positive integer bb, aba^b represents the product of bb copies of aa (the result is unique due to associativity).

Two ordered pairs (x,y)(x,y) and (a,b)(a,b) are considered identical under modulo pp if and only if

a×yx×b(modp).a \times y \equiv x \times b \pmod{p}.

Note: This "identity" is not necessarily transitive.

Fuyune provides a sequence of nn ordered pairs aa.

She asks Kazuho to determine the maximum number of length-nn positive integer sequences bb that can be selected such that for each bb, the products i=1naibi\prod_{i=1}^n a_i^{b_i} are pairwise distinct under modulo pp. It is guaranteed that pp is a prime.

Compute the sum of the answers for all intervals [l,r][l, r] (where 1lrn1 \le l \le r \le n), modulo 109+710^9+7.

Input Format

  • The first line contains two integers nn and pp. It is guaranteed that pp is a prime.
  • The next nn lines each contain two integers xix_i and yiy_i, representing the ordered pair ai=(xi,yi)a_i = (x_i, y_i).

Output Format

A single integer, the sum of answers for all intervals modulo 109+710^9+7.

2 5
3 4
2 3

6

7 3
2 2
1 2
1 0
2 1
1 1
2 1
2 0

30

8 935259307
761834349 406479726
404588595 588271872
835094749 847811683
52046622 489905911
530455310 402465343
616226641 808848730
891363714 745033395
207684362 101456684

46008831

Hint

Sample Explanation #1

  • For interval [1,1][1,1], the answer is 44. One valid selection includes sequences {1},{2},{3},{4}\{1\}, \{2\}, \{3\}, \{4\}.
  • For interval [1,2][1,2], the answer is 11. One valid selection is {1,1}\{1,1\}.
  • For interval [2,2][2,2], the answer is 11. One valid selection is {1}\{1\}.

Data Range

This problem uses subtasks with bundled testing.

  • Subtask 1 (4 pts): n2n \le 2, p5p \le 5.
  • Subtask 2 (8 pts): n5n \le 5, p5p \le 5.
  • Subtask 3 (5 pts): xi=pyix_i = p - y_i.
  • Subtask 4 (3 pts): xi=yix_i = y_i.
  • Subtask 5 (21 pts): xi=yi1x_i = y_i - 1.
  • Subtask 6 (7 pts): p=2p = 2.
  • Subtask 7 (6 pts): p=5p = 5.
  • Subtask 8 (7 pts): p5003p \le 5003.
  • Subtask 9 (8 pts): p109+7p \le 10^9+7.
  • Subtask 10 (14 pts): p1012+39p \le 10^{12}+39.
  • Subtask 11 (17 pts): No additional constraints.

For all test cases:
1n1051 \le n \le 10^5,
2p1014+672 \le p \le 10^{14}+67,
0xi,yi<p0 \le x_i, y_i < p.
It is guaranteed that pp is a prime.

Translation by DeepSeek R1