题意:

给一个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. Antd将Table导出为Excel

    Antd将Table导出为Excel 在最近的项目中,需要把表格中的数据导出给财务进行统计,网上很多一键导出的按钮都没用.经过东拼西凑,最终搞定了导出,自己封装了组件. import { File } ...

  2. 2018 东北地区大学生程序设计竞赛(ABEHIK)

    HDU6500:Problem A. Game with string 题意: 给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加 ...

  3. 在idea中运行GitHub项目

    1.首先在本地建一个文件夹,比如qm 2. 在GitHub中找到你所运行项目的路径 3.在idea中[File]-->[New]--->[Project from Version Cont ...

  4. “云”端的语雀:用 JavaScript 全栈打造商业级应用

    作者|  不四(死马)蚂蚁金服 语雀产品技术负责人 语雀是什么? 语雀是一个专业的云端知识库,面向个人和团队,提供与众不同的知识管理,打造轻松流畅的工作协同,它提供各种格式的在线文档(富文本.表格.设 ...

  5. floj 2264

    2.公路建设(highway.c/cpp/pas) 在滨海市一共有n 个城市,编号依次为1到n,它们之间计划修建m条双向道路,其中修建第i条道路的费用为ci. 海霸王作为滨海市公路建设项目的总工程师, ...

  6. TensorFlow——TensorBoard可视化

    TensorFlow提供了一个可视化工具TensorBoard,它能够将训练过程中的各种绘制数据进行展示出来,包括标量,图片,音频,计算图,数据分布,直方图等,通过网页来观察模型的结构和训练过程中各个 ...

  7. Scala实践5

    一.Scala的层级 1.1类层级 Scala中,Any是所其他类的超类,在底端定义了一些有趣的类NULL和Nothing,是所有其他类的子类. 根类Any有两个子类:AnyVal和AnyRef.其中 ...

  8. APICloud开发者进阶之路 | UIPickerView 模块示例demo

    本文出自APICloud官方论坛 rongCloud2  3.2.8 版本更新后添加了发送小视频接口,发送文件接口. rongCloud2  概述 融云是国内首家专业的即时通讯云服务提供商,专注为互联 ...

  9. cogs 173. 词链 字典树模板

    173. 词链 ★★☆   输入文件:link.in   输出文件:link.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]给定一个仅包含小写字母的英文单词表,其中每个 ...

  10. 幽灵java进程引起的: FATAL ERROR in native method

    FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT( ...