Count Pairs
**Codeforces:1189B Count Pairs**
You are given a prime number p, n integers a1,a2,…,an, and an integer k.
Find the number of pairs of indexes (i,j) (1≤i<j≤n) for which (ai+aj)(ai^ 2 + aj^ 2)≡k mod p.
Input
The first line contains integers n,p,k (2≤n≤3⋅10^ 5, 2≤p≤10^9, 0≤k≤p−1). pp is guaranteed to be prime.
The second line contains nn integers a1,a2,…,an (0≤ai≤p−10≤ai≤p−1). It is guaranteed that all elements are different.
Output
Output a single integer — answer to the problem.
Examples
input
3 3 0
0 1 2
output
1
input
6 7 2
1 2 3 4 5 6
output
3
Note
In the first example:
(0+1)(0^2 + 1 ^2)=3≡1mod3.
(0+2)(0^2 + 2 ^2)=8≡2mod3.
(1+2)(1^2 + 2 ^2)=15≡0mod3.
So only 1 pair satisfies the condition.
In the second example, there are 3 such pairs: (1,5), (2,3), (4,6).
思路:原式:(x+y)(x^ 2 + y^2)%p=k%p,将等式两边同时乘以(x-y)就行,得到:x ^ 4%p-kx%p=y ^ 4%p-ky%p;
因为x^4%p-k*x%p可能小于0;所以要在加个p,具体看代码:
#include <bits/stdc++.h>using namespace std;typedef long long ll;map<ll,int>mp;ll num[300010];int main(){long long a,n,p,k;scanf("%lld%lld%lld",&n,&p,&k);for(int i=0;i<n;i++){scanf("%lld",&num[i]);a=num[i];mp[(a*a%p*a%p*a%p-(k*a%p)+p)%p]++;}ll ans=0;for(ll i=0;i<n;i++){a=num[i];ans+=mp[(a*a%p*a%p*a%p-(k*a%p)+p)%p]-1;}printf("%lld\n",ans/2);return 0;}
Count Pairs相关推荐
- 【CF 1188 A1,B,C】Add on a Tree // Count Pairs // Array Beauty
传送门 这些天风也温柔,题也温柔 开车啦! 文章目录 A1:Add on a Tree 题意翻译 题解 证明 代码实现 B:Count Pairs 题意翻译 题解 代码实现 C:Array Beaut ...
- LeetCode——1803. 统计异或值在范围内的数对有多少(Count Pairs With XOR in a Range)[困难]——分析及代码(Java)
LeetCode--1803. 统计异或值在范围内的数对有多少[Count Pairs With XOR in a Range][困难]--分析及代码[Java] 一.题目 二.分析及代码 1. 暴力 ...
- LeetCode 1885. Count Pairs in Two Arrays(二分查找)
文章目录 1. 题目 2. 解题 1. 题目 Given two integer arrays nums1 and nums2 of length n, count the pairs of indi ...
- RxSwift之深入解析Subject的使用和实现原理
一.Subject RxSwift 的核心逻辑 Observable 不具备发送事件的能力,创建一个 Observable 的时候就要预先将要发出的数据都准备好,等到有人订阅它时再将数据通过 Even ...
- Codeforces Round #572 (Div. 2)(ABCD1D2E)
Keanu Reeves CodeForces - 1189A After playing Neo in the legendary "Matrix" trilogy, Keanu ...
- Spark RDD Action 简单用例(一)
collectAsMap(): Map[K, V] 返回key-value对,key是唯一的,如果rdd元素中同一个key对应多个value,则只会保留一个./** * Return the key- ...
- Trim or Discard or Unmap
trim 是ata 的一个指令,对应scsi指令是unmap,那么什么是trim呢? trim就是OS发送给ssd or other type controller, 告诉它哪些数据对应的LBA地址 ...
- swapLexOrder
给定一个字符串str和字符串对应的可以交换位置的下表数组pairs,求交换之后字典顺序最大的字符串(facebook笔试题). - 题目可能说的不是很明了,看个例子就很清楚要做什么了 - 给定一个字符 ...
- CF刷题(03)——难度2100~2400
这个博客记录2100到2400共17个题 2100 1.B. Maximum Value 题意:You are given a sequence a consisting of nnn integer ...
最新文章
- Mysql中对table的操作问题
- ARC与非ARC混编
- 史上第二走心的 iOS11 Drag Drop 教程
- windows和linux主机名,windows和linux下如何远程获取操作系统版本和主机名
- Tarjan的求双连通分量算法
- php中$_get和$_post如何使用,怎么使用超级全局变量$_POST与$_GET
- 2017.9.6数学
- leetcode 77. 组合 思考分析
- 解决开ServiceHost时候System.PlatformNotSupportedException: Operation is not supported on this platform.
- JavaScript 类型判断的那些事
- 从其他文件夹导入文件
- d3_3 ATM模拟系统
- 一步步学Qt,第九天-QSTL与STL-Qvector,vector
- 2018年数学建模美赛B题做题思路和详细分析(五)
- matlab 函数怎么写,MATLAB怎样定义函数(入门) 有一函数 f(x,y)=x^2+sinxy+2y , 写一程序, 输入自变量的值,输出函数值....
- activex 控件 过期_IE浏览器阻止过期ActiveX控件或将影响网银的使用-银行控件蓝屏...
- 疯狂模渲大师体验版安装教程|效果图设计师怎么安装并注册3dmax疯狂模渲大师体验版?
- 论文研究结论怎么写?
- 深度学习及机器学习整理--多谢各个网络大神
- IOS -- 获取用户的健康数据的运动步数
热门文章
- 燃爆2022年的微服务架构
- java piggy,PiggyMetrics windows 部署
- clang: error: no input files_微软商城上架Windows文件管理器:Files-UWP体验
- git restore指令和git restore --staged 的使用
- pycharm使用虚拟环境时出现的那些问题
- 数字IC后端实现TOP Floorplan专家秘籍
- 方程求解的实验 matlab,matlab 实验四 求微分方程的解
- 变形金刚2幕后制作解密
- java一键换壁纸_Java 版下载必应每日壁纸并自动设置 Windows 系统桌面(改编自 C# 版)...
- 对8421码,5421码,2421码,余3码的认识