F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Houraisan Kaguya

Time 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
4 5 1 2 3 4
 

Sample Output
4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:56:22, Gzip enabled