【题目描述】

给定一个质数 \(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;
}

CF1188B Count Pairs的更多相关文章

  1. [CF1188B]Count Pairs 题解

    前言 这道题目是道好题. 第一次div-2进前100,我太弱了. 题解 公式推导 我们观察这个式子. \[(a_i+a_j)(a_i^2+a_j^2)\equiv k \mod p\] 感觉少了点什么 ...

  2. [MeetCoder] Count Pairs

    Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at po ...

  3. CodeForces - 1189E Count Pairs(平方差)

    Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Fi ...

  4. CF1188B/E Count Pairs(数学)

    数同余的个数显然是要把\(i,j\)分别放到\(\equiv\)的两边 $ (a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p $ 左右两边乘上\((a_i-a_j ...

  5. CodeForces - 1189 E.Count Pairs (数学)

    You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the numbe ...

  6. Codeforces 1189E. Count Pairs

    传送门 可以算是纯数学题了吧... 看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘 那么 $(a_i+a_j)(a_i^2+a_j^2) \equiv  ...

  7. Codeforces 1188B Count Pairs (同余+分离变量)

    题意: 给一个3e5的数组,求(i,j)对数,使得$(a_i+a_j)(a_i^2+a_j^2)\equiv k\ mod\ p$ 思路: 化简$(a_i^4-a_j^4)\equiv k(a_i-a ...

  8. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

  9. [Swift]LeetCode373. 查找和最小的K对数字 | Find K Pairs with Smallest Sums

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

随机推荐

  1. Bootstrap4 入门

    http://www.runoob.com/bootstrap4/bootstrap4-navs.html 共五个部分 1 <!DOCTYPE html> <html lang=&q ...

  2. MLP神经网络实例--手写识别

    1.导入MNIST数据集 直接使用fetch_mldata会报错,错误信息是python3.7把fetch_mldata方法移除了,所以需要单独下载数据集从这个网站上下载数据集: https://gi ...

  3. 二、openfeign生成并调用客户端动态代理对象

    所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 上一篇文章中,我们了解到了@FeignClient注解的接口被扫描到以后,会生成一个Fe ...

  4. K2 BPM_采购端到端解决方案,激活合规采购新动能_十年专注业务流程管理系统

    「方案背景」企业管理标准化演进之路 企业的成长离不开标准化,企业的可持续发展更离不开标准化.随着市场竞争的日趋激烈,标准化已经成为企业参与市场竞争的战略性手段,也成为企业可持续发展的重要手段.聚焦到采 ...

  5. C++ 虚表虚函数怎么就实现了多态?

    虚表vftable,编译器为每个拥有虚函数的类都建有一张虚函数表,里面存有虚函数的入口指针(地址).在类对象的内存布局中,先是一个vfptr虚表指针,指向虚表首地址,而后通过偏移量的形式来访问虚表中的 ...

  6. 100行代码打造属于自己的代理ip池

    经常使用爬虫的朋友对代理ip应该比较熟悉,代理ip就是可以模拟一个ip地址去访问某个网站.我们有时候需要爬取某个网站的大量信息时,可能由于我们爬的次数太多导致我们的ip被对方的服务器暂时屏蔽(也就是所 ...

  7. Computer Vision_33_SIFT:An efficient SIFT-based mode-seeking algorithm for sub-pixel registration of remotely sensed images——2015

    此部分是计算机视觉部分,主要侧重在底层特征提取,视频分析,跟踪,目标检测和识别方面等方面.对于自己不太熟悉的领域比如摄像机标定和立体视觉,仅仅列出上google上引用次数比较多的文献.有一些刚刚出版的 ...

  8. C++——overloading

    参考 C++——overloading principle analysis operator overloading C语言中,对一个东西进行操作一定要涉及到一个函数,对于自定义类型,为了实现其四则 ...

  9. 修改gitlab配置文件指定服务器ip和自定义端口:

    修改gitlab配置文件指定服务器ip和自定义端口: vim /etc/gitlab/gitlab.rb gitlab-ctl reconfiguregitlab-ctl restart 查看与rpm ...

  10. python 获取本机的 IP 地址,windows,linux均可

    #encoding=utf-8 #参考csdn某篇文章 import socket def get_host_ip(): """ 查询本机ip地址 :return: ip ...