AtCoder Beginner Contest 335(Sponsored by Mynavi)
G
Discrete Logarithm Problems
AtCoder
⌀ 2614
原题
翻译中…

Problem Statement

翻译中…

You are given $N$ integers $A_1,\ldots,A_N$ and a prime number $P$. Find the number of pairs of integers $(i,j)$ that satisfy both of the following conditions:

翻译中…
  • $1 \leq i,j \leq N$;
  • There is a positive integer $k$ such that $A_i^k \equiv A_j \mod P$.
翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i < P$
  • $2 \leq P \leq 10^{13}$
  • $P$ is prime.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N P
A_1 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3 13
2 3 5
Output #1
5
Five pairs satisfy the conditions: $(1,1),(1,2),(1,3),(2,2),(3,3)$. For example, for the pair $(1,3)$, if we take $k=9$, then $A_1^9 = 512 \equiv 5 = A_3 \mod 13$.
Input #2
5 2
1 1 1 1 1
Output #2
25
Input #3
10 9999999999971
141592653589 793238462643 383279502884 197169399375 105820974944 592307816406 286208998628 34825342117 67982148086 513282306647
Output #3
63
题目信息
题号
abc335_g
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。