OUC 假期

一道数学题,乘以ai - aj 用平方差,O(n)解决

#include<bits/stdc++.h>
#define MAX 300010
using namespace std;
typedef long long ll;
 
ll a[MAX];
 
int main()
{
	ios::sync_with_stdio(false);
    ll n,p,k;
    cin >> n >> p >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        a[i]=(a[i]*a[i]%p*a[i]%p*a[i]%p-k*a[i]%p+p)%p;
    }
    sort(a + 1, a + n + 1);
    ll temp = 0, ans = 0;
    for(int i = 2; i <= n; i++){
        if(a[i-1] == a[i]){
            temp++;
            ans+=temp;
        }
        else temp=0;
    }
    cout << ans << endl;
    return 0;
}

 

posted @ 2019-07-13 22:26  LightAc  阅读(150)  评论(0编辑  收藏  举报
返回顶端