Count Pairs

该博客主要介绍了如何解决Codeforces上的1189B问题,即给定质数p,n个整数a1到an和整数k,找出满足特定模运算条件的数对(i, j)的数量。通过数学转化,将原问题转换为求解x^4 % p - k * x % p = y^4 % p - k * y % p的方程,讨论了处理可能小于0的情况。并给出了样例解释及解决方案。" 131132184,8579940,使用Java生成与解密二维码,"['Java开发', '二维码生成', '文件操作', '服务器存储', '图像处理']
摘要由CSDN通过智能技术生成
**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,具体看代码:

	
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值