#P7328. 「MCOI-07」Dream and Machine Learning

「MCOI-07」Dream and Machine Learning

Description

Dream built a redstone computer to verify formulas of the form ber(modm)b^e\equiv r\pmod m.
Dream fixed bb and mm, and constructed nn pairs of positive integers (e,r)(e,r) that satisfy the condition above.
Unfortunately, Dream forgot the exact value of mm. Now he gives you bb and these nn pairs. Please replace Dream's computer and answer qq queries of the form bai(modm)b^{a_i}\pmod m.

Input Format

The first line contains three positive integers, representing bb, nn, and qq.
The next nn lines each contain two positive integers, representing a pair ee and rr.
The next qq lines each contain one positive integer, representing an aia_i.

Output Format

Output qq lines, each being the answer to the corresponding query.

3 8 3
108 75
616 36
220 16
37 66
114 64
514 24
1919 65
810 33
19260817
123456789
23333333

3
79
49
请见附件 sample.in
请见附件 sample.out

Hint

Explanation for Sample 1

You can uniquely determine that m=97m=97.
Sample 1 only explains the problem statement, and does not represent any test point of any subtask.

Constraints

This problem uses bundled testcases.

  • Subtask 1 (5 pts): m103m\le10^3
  • Subtask 2 (19 pts): m109m\le10^9
  • Subtask 3 (19 pts): m1019m\le10^{19}
  • Subtask 4 (19 pts): m1029m\le10^{29}
  • Subtask 5 (19 pts): m1099m\le10^{99}
  • Subtask 6 (19 pts): m10199m\le10^{199}

For 100%100\% of the testdata, b{2,3}b\in\{2,3\}, 1q1001\le q\le100, 2e,ai1092\le e,a_i\le 10^9, and n=105n=10^5.
It is guaranteed that mm is a prime number.
It is guaranteed that all ee are pairwise distinct.
It is guaranteed that the testdata is random.

Translated by ChatGPT 5