标签:src space return cout syn its define ace mic
一道数学题,乘以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; }
标签:src space return cout syn its define ace mic
原文地址:https://www.cnblogs.com/lightac/p/11182373.html