CF1188B Count Pairs
【题目描述】
给定一个质数 \(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)\):
\]
移项变换一下可得:
\]
然后答案就呼之欲出了——把每个\(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的更多相关文章
- [CF1188B]Count Pairs 题解
前言 这道题目是道好题. 第一次div-2进前100,我太弱了. 题解 公式推导 我们观察这个式子. \[(a_i+a_j)(a_i^2+a_j^2)\equiv k \mod p\] 感觉少了点什么 ...
- [MeetCoder] Count Pairs
Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at po ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces 1189E. Count Pairs
传送门 可以算是纯数学题了吧... 看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘 那么 $(a_i+a_j)(a_i^2+a_j^2) \equiv ...
- 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 ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- [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 ...
随机推荐
- win10下,cmd,power shell设置默认编码为‘UTF-8
power shell 注:以下内容在非Windows平台上写的,可能会有拼写错误,如果有,请指正,我会尽快修正.可以用Powershell的配置文件(\(PROFILE)来实现.\)PROFILE默 ...
- 弹性布局flex 介绍
摘自:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html 网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模 ...
- js入门之内置对象Date
一. Date对象 Math和Date对象的区别 Math对象和Date对象的区别 Math不是一个构造函数,里面提供的是静态成员 Date是一个构造函数 首先要通过new Date() 来创建日期实 ...
- Linux-开机启动程序
尝试一下几种方法: 1.修改 /etc/rc.local文件. 在exit0 前添加启动命令 2.在/home/pi/.config/autostart/ 下添加.desktop 在.config ...
- java - day014 - 编译期,运行期
编译期 静态成员 私有变量 成员变量 运行期 非静态方法 package day1401; public class Test1 { public static void main(String[] ...
- 用ffserver实现rtsp服务器的实验笔记
参考:https://blog.csdn.net/hoyjam1/article/details/51281679 建议配置文件:/etc/config/ffserver.conf Port 1053 ...
- React组件的定义、渲染和传值总结
一.组件的定义 1.使用JavaScript函数定义 Welcome.js import React from 'react'; function Welcome() { return ( <d ...
- 容器上使用Docker还是Rocket?为什么不一起用呢?
在2014年接近尾声时,CoreOS在Docker发布了Rocket,声称Docker的流程模型有着“根本性的缺陷”.虽然CoreOS的创始人Alex Polvi尽量缓和语气,但是他坚持自己的基本观点 ...
- pid 及参数调试方法
所谓PID指的是Proportion-Integral-Differential.翻译成中文是比例-积分-微分. 记住两句话: 1.PID是经典控制(使用年代久远) 2.PID是误差控制() 对直流电 ...
- [cf920E][set+dfs]
https://codeforc.es/contest/920/problem/E E. Connected Components? time limit per test 2 seconds mem ...