传送门

可以算是纯数学题了吧...

看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘

那么 $(a_i+a_j)(a_i^2+a_j^2) \equiv  k \mod P$ 其实相当于 $(a_i+a_j)(a_i-a_j)(a_i^2+a_j^2) \equiv  k(a_i-a_j) \mod P$

$(a_i^2-a_j^2)(a_i^2+a_j^2)\equiv k(a_i-a_j) \mod P$

$(a_i^4-a_j^4)\equiv ka_i-ka_j \mod P$

$a_i^4-ka_i\equiv a_j^4-ka_j \mod P$

所以就做完了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=3e5+;
int n,P,K;
map <int,int> cnt;
ll ans;
int main()
{
n=read(),P=read(),K=read();
for(int i=;i<=n;i++)
{
int x=read();
x=(1ll*x*x%P*x%P*x%P-1ll*x*K%P+P)%P;
ans+=cnt[x]; cnt[x]++;
}
printf("%lld\n",ans);
return ;
}

Codeforces 1189E. Count Pairs的更多相关文章

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

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

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

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

  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 - 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 D. Count Good Substrings

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

  7. Codeforces 159D Palindrome pairs

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

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

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

  9. [CF1188B]Count Pairs 题解

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

随机推荐

  1. Java编程思想代码环境配置

    官方代码网站已更改 https://github.com/BruceEckel/TIJ4-code 如果导入到IntelliJ中 方法1 在IntelliJ中新建一个Java项目将TIJ4-code- ...

  2. 如何选CDN:互联网大直播时代的CDN选择指南

    转: 如何选CDN:互联网大直播时代的CDN选择指南 from:  http://www.chnvideo.com/blog-classic-cdn.html SRS 编码器   如何选CDN:互联网 ...

  3. OUC_Summer Training_ DIV2_#13 723afternoon

    A - Shaass and Oskols Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  4. tp5 模型关联,多表联查实用方法

    1.模型中建立关联关系 public function goods(){ return $this->belongsTo('app\common\model\goods\Goods', 'goo ...

  5. Python 文件writelines() 方法和处理双层列表

    概述 writelines() 方法用于向文件中写入一序列的字符串. 这一序列字符串可以是由迭代对象产生的,如一个字符串列表. 换行需要制定换行符 \n. 语法 writelines() 方法语法如下 ...

  6. 博客&git收藏

    阿里中间件团队博客 http://jm.taobao.orgkimmking https://blog.csdn.net/KimmKing/article/details/71517053 greys ...

  7. MACBOOK 破解wifi密码

    MACBOOK 破解wifi密码 Table of Contents 1. 安装homebrew 2. 安装aircrack-ng 3. 获取wifi网卡信息 4. 获取所有可识别的wifi信息 5. ...

  8. Python数据分析中 DataFrame axis=0与axis=1的理解

    python中的axis究竟是如何定义的呢?他们究竟代表是DataFrame的行还是列? 直接上代码people=DataFrame(np.random.randn(5,5), columns=['a ...

  9. Swift3.0添加桥接文件

    注意是在target下不是project !!!纠结了好久表示...... 都这里一直编译错误,找不到该桥接文件,这里也是纠结了好久......最后原因是不能使用下划线就可以了....<表示这是 ...

  10. 九大内置对象 and HTTP略微的个人见解

    jsp 中九大内置对象: 请求对象:request      输出对象:out         响应对象:response      应用程序对象:application      会话对象:sess ...