题意:

给一个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_j)\ mod\ p$

分离变量$a_i^4-ka_i\equiv (a_j^4-ka_j)\ mod\ p$

于是就变成了常规题

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
//#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);
ll a[maxn];
map<ll, ll>ma;
int main(){
ll n, p, k;
scanf("%lld %lld %lld", &n, &p, &k);
for(int i = ; i <= n; i++){
scanf("%lld", &a[i]);
ll x = a[i];
ll res = x*x%p*x%p*x%p-k*x%p;
res=(res+p)%p;
ma[res]++;
}
ll ans = ;
for(auto it = ma.begin(); it != ma.end(); it++){
ll x = (*it).sc;
//printf("%lld %lld\n", (*it).fst, x);
ans+=(x-)*x/;
}
printf("%lld",ans);
return ;
} /*
*/

Codeforces 1188B Count Pairs (同余+分离变量)的更多相关文章

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

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

  2. 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 ...

  3. Codeforces 1189E. Count Pairs

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

  4. [MeetCoder] Count Pairs

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

  5. codeforces#572Div2 E---Count Pairs【数学】【同余】

    题目:http://codeforces.com/contest/1189/problem/E 题意:给定$n$个互不相同数,一个$k$和一个质数$p$.问这$n$个数中有多少对数$(a_i+a_j) ...

  6. 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 ...

  7. codeforces D. Count Good Substrings

    http://codeforces.com/contest/451/problem/D 题意:给你一个字符串,然后找出奇数和偶数长度的子串的个数,这些字串符合,通过一些连续相同的字符合并后是回文串. ...

  8. Codeforces 159D Palindrome pairs

    http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...

  9. 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 ...

随机推荐

  1. AnyDesk免费远程工具

    AnyDesk是一款声称速度最快的免费长途衔接/长途桌面操控软件,是前TeamViewer开发小组人员自立门户的商品,它拥有领先的视频压缩技能DeskRT,能够轻松穿透防火墙/路由器,实测在电信.移动 ...

  2. 【python小随笔】动态创建变量名

    PS:有时候我们不知道列表组数里存放几个值,但是又要动态的遍历这些值并且动态的创建每一个对应的一个变量里: t = ['B0716PK6R2','B077X9J24C','B01N2SBH4J'] c ...

  3. Spring中PropertiesLoaderUtils应用

    FileSystemResource fileSystemResource =new FileSystemResource("D:/home/conf/mail.properties&quo ...

  4. C语言之运算符和表达式

    运算符优先级: 求余运算用法: 声明变量的名字和类型: 变量的类型决定占用内存空间的大小.数据的存储形式,合法的表数范围.可参与的运算种类.变量名标识了内存中的一个存储单元. 自动类型转换: 运算符和 ...

  5. pandas操作mysql从放弃到入门

    目录 相关帮助文档 一.如何读取数据库-read_sql 二.如何筛选数据 三.如何连表-merge 四.如何删除一行或一列-drop 五.如何分组统计-groupyby 六.如何排序-sort_va ...

  6. android:整理drawable(shapdrawable)(二)

    前言 bitmapdrawable 与nithpathdrawable 完结,接下来是shapedrawable. shapedrawable是使用频率最高的drawable 可见其重要性. shap ...

  7. 图解kubernetes调度器抢占流程与算法设计

    抢占调度是分布式调度中一种常见的设计,其核心目标是当不能为高优先级的任务分配资源的时候,会通过抢占低优先级的任务来进行高优先级的调度,本文主要学习k8s的抢占调度以及里面的一些有趣的算法 1. 抢占调 ...

  8. 【UWP】使用 LiteDB 存储数据

    序言: 在 UWP 中,常见的存储数据方式基本上就两种.第一种方案是 UWP 框架提供的 ApplicationData Settings 这一系列的方法,适用于存放比较轻量的数据,例如存个 Bool ...

  9. 如何通过Java8的方式去统计程序执行时间?

    代码如下所示 import java.time.Duration; import java.time.Instant; import java.util.concurrent.TimeUnit; pu ...

  10. Docker学习(十)Docker容器编排 Docker-compose

    Docker学习(十)Docker容器编排 Docker-compose 标签(空格分隔): docker 容器编排是什么 应用一般由单独容器化的组件组成,须按照一定顺序在网络级别进行组织,以使其能够 ...