luogu#P12011. 【MX-X10-T7】[LSOT-4] 春开,意遥遥。
【MX-X10-T7】[LSOT-4] 春开,意遥遥。
Background
Spring has come true?
This problem was originally prepared by Fuyune for Kazuho during a certain cycle of time but was replaced with a shogi problem due to the author's concern about the difficulty of OI problems. After 12 years, the original problem is now released here.
Problem 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 and a positive integer , represents the product of copies of (the result is unique due to associativity).
Two ordered pairs and are considered identical under modulo if and only if
Note: This "identity" is not necessarily transitive.
Fuyune provides a sequence of ordered pairs .
She asks Kazuho to determine the maximum number of length- positive integer sequences that can be selected such that for each , the products are pairwise distinct under modulo . It is guaranteed that is a prime.
Compute the sum of the answers for all intervals (where ), modulo .
Input Format
- The first line contains two integers and . It is guaranteed that is a prime.
- The next lines each contain two integers and , representing the ordered pair .
Output Format
A single integer, the sum of answers for all intervals modulo .
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 , the answer is . One valid selection includes sequences .
- For interval , the answer is . One valid selection is .
- For interval , the answer is . One valid selection is .
Data Range
This problem uses subtasks with bundled testing.
- Subtask 1 (4 pts): , .
- Subtask 2 (8 pts): , .
- Subtask 3 (5 pts): .
- Subtask 4 (3 pts): .
- Subtask 5 (21 pts): .
- Subtask 6 (7 pts): .
- Subtask 7 (6 pts): .
- Subtask 8 (7 pts): .
- Subtask 9 (8 pts): .
- Subtask 10 (14 pts): .
- Subtask 11 (17 pts): No additional constraints.
For all test cases:
,
,
.
It is guaranteed that is a prime.
Translation by DeepSeek R1