TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

100.0% (1/1)

Tags

Description

Given a prime $P$ and one of its primitive roots $g$, and $n$ positive integers $\lbrace a_ i\rbrace_ {i=0}^ {n-1}$, for each $a_ i$ output the minimum non-negative integer $b_ i$ that satisfies $g^ {b_ i}\equiv a_ i\pmod P$.

Input Format

$P$ $g$ $n$
$a_ 0$
$a_ 1$
:
$a_ {n-1}$

Output Format

$b_ 0$
$b_ 1$
:
$b_ {n-1}$

Sample Input 1

998244353 3 6
1
3
9
27
578373382
100

Sample Output 1

0
1
2
3
100
500620418

Hints

  • $2\le P\le10^ 9$
  • $P$ is a prime
  • $1\le n\le10^ 6$
  • $1\le a_ i<P$

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 2097152 2097152
1 5000 2097152 2097152
2 5000 2097152 2097152
3 5000 2097152 2097152
4 5000 2097152 2097152
5 5000 2097152 2097152
6 5000 2097152 2097152
7 5000 2097152 2097152
8 5000 2097152 2097152
9 5000 2097152 2097152
10 5000 2097152 2097152
11 5000 2097152 2097152
12 5000 2097152 2097152
13 5000 2097152 2097152
14 5000 2097152 2097152
15 5000 2097152 2097152
16 5000 2097152 2097152
17 5000 2097152 2097152
18 5000 2097152 2097152
19 5000 2097152 2097152
20 5000 2097152 2097152
21 5000 2097152 2097152
22 5000 2097152 2097152
23 5000 2097152 2097152