【题目描述】

给定一个质数 \(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. mybatisplus 使用案例

    案例地址 https://github.com/qixianchuan/SpringBootQD/tree/master/mybatisplus

  2. iOS退出APP

    强制退出有四种: exit(); abort(); assert(); 主动制造一个崩溃: exit() 1.附加了关闭打开文件与返回状态码给执行环境,并调用你用atexit注册的返回函数: 2.警告 ...

  3. S3C2440 OpenJtag

    C:\Users\Administrator\Desktop>oflash.exe leds.bin +--------------------------------------------- ...

  4. node.js 微信开发1-接入

    准备工作1 域名准备 无论是个人开发还是做公司项目域名都是必不可少的 前期我个人用过花生壳做个开发测试,挺好用的,就是现在要收费了,开通花生壳要收费,开通内网穿透要收费(为啥要内网穿透呢,因为微信接入 ...

  5. LInux设置tomcat端口为80

    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...

  6. Cron 定时任务表达式

    Cron Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth M ...

  7. LTS秘钥协商算法分析

    1.根据RCF文档说法 在1-RTT中有两种密钥协商算法(1-RTT ECDHE和 1-RTT PSK  )和4中0-RTT密钥协商方式(0-RTT PSK, 0-RTT ECDH ,0-RTT EC ...

  8. zookeeper服务【-】windows安装与liunx安装

    windows安装zookeeper-3.4.14 https://www.apache.org/dyn/closer.cgi/zookeeper/ [zookeeper下载地址] 1.开启服务之前需 ...

  9. DDD:架构思想的旧瓶新酒

    DDD.DSL 和 DCI DDD 概念最早提出于 2004 年,作为一种软件开发的指导思想,DDD 对软件开发带来了诸多可能与方向,张晓龙认为 DDD 为软件开发带来的好处主要有以下几点: 首先,最 ...

  10. 单链表(python)

    # -*- coding: utf-8 -*- class Node(object): def __init__(self, value=None, next=None): # 这里我们 root 节 ...