|
||||||||||
Houraisan KaguyaTime Limit: 18000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 105 Accepted Submission(s): 12 Problem Description Houraisan Kaguya is fighting against Fujiwara no Mokou over the moon. Suddenly, Mokou launches a spell ¡°Imperishable Shooting¡±(just a programming problem, believe it or not) to attack Kaguya, which is as follows. Given a prime number p and n positive integers a1, a2, ¡¤ ¡¤ ¡¤ , an which are strictly less than p. For two integers a, b (0 ¡Ü a, b < p), we say a is representable by b if and only if there exists a positive integer x that bx ¡Ô a(mod p). Furthermore, we define f(a, b) as the minimum positive integer u that au modulo p is representable by b. If no such u exists, f(a, b) is specially defined as 0. The problem is to determine the value of following formula. $$(\sum_{i=1}^{n}\sum_{j=1}^{n}f(a_i,a_j)\times f(a_j,a_i)) \mod p$$ Please help Kaguya solve it so that Kaguya can give Mokou the sixth puzzle in the next round. Input The first line contains two positive integers n, p (1 ¡Ü n ¡Ü 100 000, 2 ¡Ü p ¡Ü 1018), denoting the number of given integers and the given prime number. The next line contains n positive integers ai (1 ¡Ü ai < p), denoting the given integers. Output Output a single line containing a non-negative integer, denoting the answer. Sample Input
Sample Output
Source | ||||||||||
|