#P9816. 少项式复合幂
少项式复合幂
Background
I have won everything except your heart.
Finally, Little Z can play Genshin Impact for a year. But before that, he decided to create this problem to commemorate his feelings for [data deleted].
Problem Description
Given a polynomial . Define , and .
Given a modulus . There are queries. Each query gives , and asks for the value of .
Please note the special Constraints for .
Input Format
The first line contains three positive integers , representing the number of terms in , the number of queries, and the given modulus.
Then follow lines, each containing two non-negative integers , describing the polynomial .
Then follow lines, each containing two positive integers , representing one query.
Output Format
Output lines in total, each line containing the answer to the corresponding query.
3 5 71
1 1
3 3
1 0
7 5
9 6
10 1
5 6
7 6
27
11
29
2
5
Hint
Explanation of the Samples
In Sample 1, . Take the 3rd query as an example: $f_1(10)=f(10)=3\times10^3+10+1=3011\equiv 29 \pmod {71}$.
Constraints and Conventions
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| A | ||||
| None | ||||
| A, B | ||||
| B | ||||
| None | ||||
- Special Property A: is guaranteed to be a prime.
- Special Property B: is guaranteed.
For all testdata, it is guaranteed that , , , , and .
Translated by ChatGPT 5