题目http://codeforces.com/contest/1189/problem/E

题意:给定$n$个互不相同数,一个$k$和一个质数$p$。问这$n$个数中有多少对数$(a_i+a_j)(a_i^2+a_j^2)\equiv k\,mod\,p$

思路:这一场的题目好像都很思维啊,代码量不多,想得出来就能写。

同余式左右两边同乘一个非零的数同余式不变,所以原式可以变为

$(a_i-a_j)(a_i+a_j)(a_i^2+a_j^2)\equiv (a_i-a_j)k = (a_i^2-a_j^2)(a_i^2+a_j^2)\equiv (a_i-a_j)k = (a_i^4-a_j^4)\equiv a_ik-a_jk = a_i^4 - a_ik \equiv a_j^4 - a_jk$

所以对于每一个数我们只需要计算$a_i^4-a_ik\,mod\,p$,然后根据这个能取到这个值的集合大小来计算答案就行了。

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<iostream> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pr; int n, p, k;
const int maxn = 3e5 + ;
int num[maxn];
map<int, int>mp; int main()
{
scanf("%d%d%d", &n, &p, &k);
for(int i = ; i < n; i++){
scanf("%d", &num[i]);
int res = ((LL)num[i] * num[i] % p * num[i] % p - k) % p * num[i] % p;
res = (res + p) % p;
if(mp.find(res) != mp.end()){
mp[res] = mp[res] + ;
}
else{
mp[res] = ;
}
}
map<int, int>::iterator iter;
int ans = ;
for(iter = mp.begin(); iter != mp.end(); iter++){
int x = iter->second;
//cout<<iter->first<<":"<<iter->second<<endl;
ans += x * (x - ) / ;
}
printf("%d\n", ans);
return ;
}

最新文章

  1. WinForm中实现播放mp3 、mp4文件
  2. hashmap先按照value从大到小排序,value相等时按照key从小到大排序
  3. DedeCMS Xss+Csrf Getshell \dede\file_manage_control.php
  4. 。。。在学习新框架Spring MVC的感受。。。
  5. atitit.表格的绑定client side 最佳实践
  6. Remote Displayer for Android
  7. QTextCodec::makeDecoder函数,plugins需要是动态链接库
  8. linux mount (挂载命令)详解
  9. JSP页面上用横线代替文本框
  10. python 操作word文档
  11. codeforces 620F. Xors on Segments
  12. 利用jsoup爬取百度网盘资源分享连接(多线程)
  13. IONIC2新建项目并添加导航
  14. List集合数据太多进行分批,List的subList方法应用
  15. 初识 go 语言:方法,接口及并发
  16. python -- while循环,格式化输出,运算符,初识编码
  17. call与apply简单介绍
  18. Delphi Qjson
  19. [转]jquery设置select选中,赋值等操作
  20. 获取指定ip段的所有存活主机的主机名和操作系统

热门文章

  1. Python 常用包收集
  2. web框架解析
  3. java 简单操作HDFS
  4. Yii2.0 手动添加扩展 redis为例
  5. GRPC代替webapi Demo。
  6. IServiceBehavior IContractBehavior IEndpointBehavior IOperationBehavior
  7. Python-pptx库的运用
  8. iPhone电话与短信相关代码小结
  9. pip3升级问题
  10. 云端的ABAP Restful服务开发