【题目描述】

给定一个质数 \(p\) , 一个长度为 \(n\)n 的序列 \(a = \{ a_1,a_2,\cdots,a_n\}\)一个整数 \(k\)。

求所有数对 \((i, j)\) (\(1 \le i 、j \le n\))中满足 \((a_i + a_j) \times (a_i^2 + a_j^2 ) \equiv k (\bmod p)\)的个数。

【题解】

对于题中的柿子:

\[(a_i + a_j) \times (a_i^2 + a_j^2 ) \equiv k (\bmod p)
\]

我们可以在两边同时乘上\((a_i - a_j)\):

\[(a_i^4 - a_j^4 ) \equiv k \times (a_i - a_j) (\bmod p)
\]

移项变换一下可得:

\[a_i^4 - k \times a_i \equiv a_j^4 - k \times a_j (\bmod p)
\]

然后答案就呼之欲出了——把每个\(a_i^4 - k \times a_i\)插入\(map\)统计即可。

\(Code:\)

#include<cstdio>
#include<map>
using namespace std;
#define ll long long
#define rg register
struct ios{
template<typename TP>
inline ios operator >> (TP &x)
{
TP f=1;x=0;rg char c=getchar();
for(;c>'9' || c<'0';c=getchar()) if(c=='-') f=-1;
for(;c>='0' && c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
x*=f;
return *this;
}
template<typename TP>
inline ios operator << (TP x)
{
int top=0,s[66];
if(x<0) x=-x,putchar('-');
if(!x) putchar('0');
while(x) s[++top]=x%10+'0',x/=10;
while(top) putchar(s[top--]);
return *this;
}
inline ios operator << (char s)
{
putchar(s);
return *this;
}
}io;
const int N=3e5+5;
int n,a,k,p,ans;
map<int,int>m;
int main()
{
io>>n>>p>>k;
for(rg int i=1;i<=n;++i)
{
io>>a;
int temp=(1ll*a*a%p*a%p*a-1ll*k*a%p+p)%p;
ans+=m[temp],++m[temp];
}
io<<ans;
return 0;
}

最新文章

  1. qq空间等闪动的文字怎么做?
  2. UIBezierPath-绘制基本图形
  3. show status和show variables区别解析
  4. C# 字符串的截取和替换
  5. 第二百九十七天 how can I 坚持
  6. App接口设计原则-b
  7. 《C++ Primer Plus 6th》读书笔记 - 第九章 内存模型和名称空间
  8. python 调用图灵机器人api实现简单的人机交互
  9. FZU 1627 Revival&#39;s road
  10. doc 窗口操作图
  11. window.getSelection和document.selection
  12. SQL server 存储过程的建立和调用
  13. lua table表判断是否为空
  14. JS访问SpringMVC后台
  15. Oracle从入门到精通(详细) 明日科技
  16. VeeamOne(Free Edition 9.5 )-安装与配置
  17. commit 冲突
  18. Ecplise通过Git将项目提交到GitHub
  19. 蓝牙协议分析(11)_BLE安全机制之SM
  20. How to use CAR FANS C800 Diagnostic Scan Tool to do diagnosis operation

热门文章

  1. iOS开发 CGAffineTransform 让图片旋转, 旋转后获得图片旋转的角度
  2. Apache老版本下载地址
  3. 前台.cshtml得到cookie值方法
  4. Java--8--新特性--Stream API
  5. 系统API是原子操作吗?
  6. Pyspark:AssertionError: dataType should be DataType
  7. SpringBoot下,@WebFilter配置获取日志
  8. java线程基础巩固---多Product多Consumer之间的通讯导致出现程序假死的原因分析
  9. java kafka
  10. js rsa sign使用笔记(加密,解密,签名,验签)