当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6738:Houraisan Kaguya

题目描述
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.
输入解释
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 a single line containing a non-negative integer, denoting the answer.
输入样例
4 5
1 2 3 4
输出样例
4
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 642ccpcQHD

源链接: HDU-6738

最后修改于 2020-10-25T23:33:56+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
18000/15000MS(Java/Others) 131072/131072K(Java/Others)