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; }
作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。