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 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.
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 a single integer — answer to the problem.
3 3 0
0 1 2
1
6 7 2
1 2 3 4 5 6
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 (数学)的更多相关文章
- 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 ...
- 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 ...
- [MeetCoder] Count Pairs
Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at po ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- Codeforces 1189E. Count Pairs
传送门 可以算是纯数学题了吧... 看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘 那么 $(a_i+a_j)(a_i^2+a_j^2) \equiv ...
- 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 ...
- Codeforces 839C Journey - 树形动态规划 - 数学期望
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...
- codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- [Codeforces 1178D]Prime Graph (思维+数学)
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...
随机推荐
- 外贸电子商务网站之Prestashop paypal支付添加
1.在https://addons.prestashop.com/en/payment-card-wallet/1748-paypal.html 下载paypal支付模块 2.解压,复制到网站根目录- ...
- java 操作Oracle 批量入库的问题
java 操作Oracle 批量入库的问题 先说下我运行的环境: Windows7 64位操作系统 (四核)Intel i5-2300 CPU @2.80GHz 内存4G 硬盘1T Jdk1.6+My ...
- TIJ——Chapter Ten:Inner Classes
先提纲挈领地来个总结: 内部类(Inner Class)有四种: member inner class,即成员内部类.可以访问外部类所有方法与成员变量.生成成员内部类对象的方法:OuterClass. ...
- MySql5.7 配置文件 my.cnf 设置
https://blog.csdn.net/gzt19881123/article/details/52594783 # MySql5.7配置文件my.cnf设置 [client] port = 33 ...
- vue中$bus的传参的坑
今天在做项目的时候碰见一个坑就是B页面有个点击事件需要触发完然后跳转到A页面,接着页面跳转过去后再A页面的create生命周期中利用on监听事件的改变,接着赋值给data里面某个数据,但是奇怪的问题是 ...
- 二 virtualenv与virtualenvwrapper
https://www.cnblogs.com/pyyu/p/9015317.html 一 virtualenv 1.下载virtualenvpip3 install -i https://pypi ...
- python 替换字符串的方法replace()、正则re.sub()
一.replace()函数1用字符串本身的replace方法: a = 'hello word' b = a.replace('word','python') print b 1 2 3 二.re ...
- 瑞星推国内唯一Linux系统杀毒软件 国产操作系统还需国产安全软件保护
近来在IT领域最爆炸的新闻莫过于5月20日中央国家机关政府採购中心下发通知.要求中央机关採购所有计算机类产品不同意安装Windows 8.而改用国产Linux操作系统. 此消息一出,立马引起各界关注. ...
- 2019-3-25-win10-uwp-如何将像素数组转-png-文件
title author date CreateTime categories win10 uwp 如何将像素数组转 png 文件 lindexi 2019-3-25 8:53:1 +0800 201 ...
- Flask学习之五 用户登录
英文博客地址:http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins 中文翻译地址:http:// ...