CodeForces - 1189 E.Count Pairs (数学)

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) (1i<jn1≤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 (2n31052≤n≤3⋅105, 2p1092≤p≤109, 0kp10≤k≤p−1). pp is guaranteed to be prime.

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

Output

Output a single integer — answer to the problem.

Examples
input
Copy
3 3 0
0 1 2
output
Copy
1
input
Copy
6 7 2
1 2 3 4 5 6
output
Copy
3


题意:
问有多少对i,j,使得a[i],a[j]满足题干中的式子。
思路:
两边同乘(a[i]-a[j]),再把a[i],a[j]分到式子两边即可。

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>

#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a, x) cout<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 300086;
const int maxm = 100086;
const int inf = 0x3f3f3f3f;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1);


map<ll,ll>mp;
int main() {
//    ios::sync_with_stdio(false);
//    freopen("in.txt", "r", stdin);

    ll p,n,k;
    scanf("%lld%lld%lld",&n,&p,&k);
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ll x;
        scanf("%lld",&x);
        ll num = (x*x%p*x%p*x%p - (k*x)%p+p+p)%p;
//        fuck(num)
        ans+=mp[num];
        mp[num]++;
    }
    printf("%lld\n",ans);

    return 0;
}
View Code
posted @ 2019-07-09 16:27  断腿三郎  阅读(418)  评论(0编辑  收藏  举报