Count Pairs CodeForces - 1188B 推式子

You are given a prime number pp , nn integers a1,a2,…,ana1,a2,…,an , and an integer kk .

Find the number of pairs of indexes (i,j)(i,j) (1≤i<j≤n1≤i<j≤n ) for which (ai+aj)(a2i+a2j)≡kmodp(ai+aj)(ai2+aj2)≡kmodp .

Input

The first line contains integers n,p,kn,p,k (2≤n≤3⋅1052≤n≤3⋅105 , 2≤p≤1092≤p≤109 , 0≤k≤p−10≤k≤p−1 ). pp is guaranteed to be prime.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤p−10≤ai≤p−1 ). It is guaranteed that all elements are different.

Output

Output a single integer — answer to the problem.

Examples

Input

3 3 0
0 1 2

Output

1

Input

6 7 2
1 2 3 4 5 6

Output

3

Note

In the first example:

(0+1)(02+12)=1≡1mod3(0+1)(02+12)=1≡1mod3 .

(0+2)(02+22)=8≡2mod3(0+2)(02+22)=8≡2mod3 .

(1+2)(12+22)=15≡0mod3(1+2)(12+22)=15≡0mod3 .

So only 11 pair satisfies the condition.

In the second example, there are 33 such pairs: (1,5)(1,5) , (2,3)(2,3) , (4,6)(4,6) .

、震惊,居然是道大水题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+15;
ll a[maxn];
map<long long,long long>mp;
int main()
{
    ll n,p,k;
    cin>>n>>p>>k;
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
    {
        long long tp1=(a[i]*a[i]%p*a[i]%p*a[i]%p-k*a[i]%p+p)%p;
        mp[tp1]++;
    }
    long long ans=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        ans+=(it->second)*((it->second)-1)/2;
    }
    cout<<ans;
}

 

全部评论

相关推荐

03-03 23:12
已编辑
北京邮电大学 Java
书海为家:我来给一点点小建议,因为毕竟还在学校不像工作几年的老鸟有丰富的项目经验,面试官在面试在校生的时候更关注咱们同学的做事逻辑和思路,所以最好在简历中描述下自己做过项目的完整过程,比如需求怎么来的,你对需求的解读,你想到的解决办法,遇到困难如何找人求助,最终项目做成了什么程度,你从中收获了哪些技能,你有什么感悟。
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务