题意:

给一个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. java数据结构之常用排序算法

    冒泡排序 private void maopao(int arr[]) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j &l ...

  2. 【转】利用Eclipse编辑中文资源文件(application_zh_CN.properties )

    既然生为中国人,就没有什么好抱怨的了,遇到编码的问题,那只有解决它了. 如果经常使用Struts,并做过国际化操作的人来说,对于中文资源文件的处理应该不会感到陌生的.比如下面两个文件,一个是英文的,一 ...

  3. 【转】常见Java面试题 – 第一部分:非可变性(Immutability)和对象引用(Object reference)

    ImportNew注: 本文是ImportNew编译整理的Java面试题系列文章之一.请看此系列相关面试题.你可以从这里查看全部的Java面试系列. 一些比较核心的Java问题经常会用来考验面试者的J ...

  4. C# 中 ConfigureAwait 相关答疑FAQ

    C# 中 ConfigureAwait 相关答疑FAQ 在前段时间经常看到园子里有一些文章讨论到 ConfigureAwait,刚好今天在微软官方博客看到了 Stephen Toub 前不久的一篇答疑 ...

  5. 百度DMA+小度App的蓝牙语音解决方案案例展示

    前记   跟着百度也有一段时间了,经过一年多的努力,我们也做出了一些产品.下面就给大家秀一下我们做的产品.有类似需求的朋友可以多多交流. 智能语音耳机   这个是就是可以通过按键来调用小度app的运动 ...

  6. Spring Boot 入门(十二):报表导出,对比poi、jxl和esayExcel的效率

    本片博客是紧接着Spring Boot 入门(十一):集成 WebSocket, 实时显示系统日志写的 关于poi.jxl和esayExcel的介绍自行百度. jxl最多支持03版excel,所以单个 ...

  7. QT 获取当前毫秒级时间缀

    long long currentTime = QDateTime::currentDateTime().toMSecsSinceEpoch();

  8. django cms 5月第一弹

    官方文档: ##http://django-cms.readthedocs.io/en/latest/index.html #截图 #生存的项目结构

  9. 关于 C#和.net 的 发展

    591. C# 1 的 委托 语法 看起来 似乎 并不 太坏 [2016-04-27 09:00:56]592. C# 2 支持 从 方法 组 到 一个 兼容 委托 类型 的 隐式 转换. [2016 ...

  10. springboot开发之使用外部servlet容器及对jsp的支持

    一般而言,springboot是使用自己内嵌的servlet容器,比如tomcat等等,而且默认的模板引擎是thymeleaf,那么如何让springboot使用外部的servlet容器并支持对jsp ...