You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk.

Find the number of pairs of indexes (i,j)(i,j) (1≤i<j≤n1≤i<j≤n) for which (ai+aj)(a2i+a2j)≡kmodp(ai+aj)(ai2+aj2)≡kmodp.

Input

The first line contains integers n,p,kn,p,k (2≤n≤3⋅1052≤n≤3⋅105, 2≤p≤1092≤p≤109, 0≤k≤p−10≤k≤p−1). pp is guaranteed to be prime.

The second line contains nn integers a1,a2,…,ana1,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

Copy
3 3 0
0 1 2
output

Copy
1
input

Copy
6 7 2
1 2 3 4 5 6
output

Copy
3

题意:
问有多少对i,j,使得a[i],a[j]满足题干中的式子。
思路:
两边同乘(a[i]-a[j]),再把a[i],a[j]分到式子两边即可。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime> #define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a, x) cout<<#a<<"["<<x<<"] = "<<a[x]<<endl;
#define ls (t<<1)
#define rs ((t<<1)|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); map<ll,ll>mp;
int main() {
// ios::sync_with_stdio(false);
// freopen("in.txt", "r", stdin); ll p,n,k;
scanf("%lld%lld%lld",&n,&p,&k);
ll ans = ;
for(int i=;i<=n;i++){
ll x;
scanf("%lld",&x);
ll num = (x*x%p*x%p*x%p - (k*x)%p+p+p)%p;
// fuck(num)
ans+=mp[num];
mp[num]++;
}
printf("%lld\n",ans); return ;
}

CodeForces - 1189 E.Count Pairs (数学)的更多相关文章

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

  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. [MeetCoder] Count Pairs

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

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

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

  5. Codeforces 1189E. Count Pairs

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

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

  7. Codeforces 839C Journey - 树形动态规划 - 数学期望

    There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...

  8. codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)

    题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

随机推荐

  1. CF772E Verifying Kingdom

    CF772E Verifying Kingdom 有趣的交互题(交互题都挺有意思的) %ywy 增量法构造 考虑加入了前i个叶子 那么树是前i个叶子构成的虚树! 最后n个叶子构成的虚树就是答案! 怎样 ...

  2. kendo grid 使用小结

    需要注意的: 1. id,如果没有指定id则会导致create.update等操作无法正常使用. 头疼事项: 1. 服务端失败返回error数据.如果是编辑状态,还不能友好提示错误.当然可以使用大量代 ...

  3. LeetCode208 Implement Trie (Prefix Tree). LeetCode211 Add and Search Word - Data structure design

    字典树(Trie树相关) 208. Implement Trie (Prefix Tree) Implement a trie with insert, search, and startsWith  ...

  4. 【uml】之用例图中的关系 标签: uml图形 2014-11-23 11:10 1422人阅读 评论(29)

    用例图显示谁是相关的用户,用户希望系统提供什么样的服务(用例),用例之间的关系图,用例图主要的作用是获取需求.指导测试.所以,用例图是站在用户的角度来画的图,应该体现的是用户想要的功能,并不需要体现如 ...

  5. 重磅课程|《CNCF x Alibaba 云原生技术公开课》正式开讲!

    ​ 到底什么是“云原生”?云原生与 CNCF.Kubernetes 是什么关系?作为云计算时代的开发者和从业者,我们该如何在“云原生”的技术浪潮中站稳脚跟,将云原生落地.实现个人的自我升级呢? 201 ...

  6. 配置 IO 时要记得换 Page

    配置 IO 时要记得换 Page 在配置某些芯片时,配置 IO 时要记得换页,不然不生效. 注意查看 IO 的相关规格书说明,而且每个厂商是不一样的.

  7. oralce GROUPING

    /*从上面的结果中我们很容易发现,每个统计数据所对应的行都会出现null, 如何来区分到底是根据那个字段做的汇总呢,grouping函数判断是否合计列!*/ select decode(groupin ...

  8. Python基础:25文件

    一:文件对象 文件对象不仅可以用来访问普通的磁盘文件, 而且也可以访问任何其它类型抽象层面上的"文件". 一旦设置了合适的"钩子", 你就可以访问具有文件类型接 ...

  9. ODT 珂朵莉树 入门

    #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> ...

  10. behavior planning——14.implement a cost function in C++

    n most situations, a single cost function will not be sufficient to produce complex vehicle behavior ...