Codeforces 1188B 式子转化
思路:看到(a + b)想到乘上(a - b)变成平方差展开(并没有想到2333), 两边同时乘上a - b, 最后式子转化成了a ^ 4 - ka = b ^ 4 - kb,剩下的就水到渠成了。
0的时候特判一下即可。
代码:
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int, int>
#define db double
using namespace std;
const int maxn = 100010;
map<int, int> mp;
int mod, n;
int qpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1) {
if(y & 1) ans = ((LL)ans * x) % mod;
x = ((LL)x * x) % mod;
}
return ans;
}
map<int, int>::iterator it;
int main() {
int x, k;
LL ans = 0;
scanf("%d%d%d", &n, &mod, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
x = (qpow(x, 4) - ((LL)k * x) % mod + mod) % mod;
mp[x]++;
}
for (it = mp.begin(); it != mp.end(); it++) {
LL tmp = it -> second;
ans += tmp * (tmp - 1) / 2;
}
if(mod == 0) {
LL tmp = mp[0];
ans += tmp * (tmp - 1) / 2;
}
printf("%lld\n", ans);
}
Codeforces 1188B 式子转化的更多相关文章
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- Codeforces 1136E(转化+线段树维护)
题目传送 虽然线段树比较显然但是发现a数组并不好维护.考虑将a转化为好维护的数组b. 方法 这里我将k[1]设为0,对应着\[a[1] + k[1] <= a[2]\]不难得出\[a[i] + ...
- Codeforces 1132E(转化+dp)
要点 假设第i个最后总共选的值为ci,不妨把它分成两部分:\[c_i=cnt'_i*L+q_i\]\[L=840,\ 0<=q_i<L\]又可以写成:\[c_i=cnt_1*i+cnt_2 ...
- Codeforces 1142C(转化、凸包)
可以变换坐标:x' = x, y' = y - x ^ 2,如此之后可得线性函数x' * b + c = y',可以发现两点连边为抛物线,而其他点都在这条线下方才满足题意,故而求一个上凸壳即可. #i ...
- 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 366C 动态规划 转化背包思想
这道题目昨晚比赛没做出来,昨晚隐约觉得就是个动态规划,但是没想到怎么DP,今天想了一下,突然有个点子,即局部最优子结构为 1-j,j<i,遍历i,每次从所有的1到j当中的最优解里面与当前商品进行 ...
- codeforces选做
收录了最近本人完成的一部分codeforces习题,不定期更新 codeforces 1132E Knapsack 注意到如果只使用某一种物品,那么这八种物品可以达到的最小相同重量为\(840\) 故 ...
- 【Codeforces Round #431 (Div. 1) D.Shake It!】
·最小割和组合数放在了一起,产生了这道题目. 英文题,述大意: 一张初始化为仅有一个起点0,一个终点1和一条边的图.输入n,m表示n次操作(1<=n,m<=50),每次操作是任选一 ...
- Codeforces Round #580 (Div. 2)
这次比上次多A了一道,但做得太慢,rating还是降了. Problem A Choose Two Numbers 题意:给出两个集合A,B,从A,B中分别选出元素a,b使得a+b既不属于集合A,又不 ...
随机推荐
- apt-get update 101错误解决办法
在一次装好Ubuntu系统, 执行 sudo apt-get update 时,报了错 " W: Failed to fetch http://security.ubuntu.com/ubu ...
- Sass函数:值列表函数length
length() 函数主要用来返回一个列表中有几个值,简单点说就是返回列表清单中有多少个值: >> length(10px) 1 >> length(10px 20px (bo ...
- HTML5:Canvas-绘制图形
到本文的最后,你将学会如何绘制矩形,三角形,直线,圆弧和曲线,变得熟悉这些基本的形状.绘制物体到Canvas前,需掌握路径,我们看看到底怎么做. 栅格 在我们开始画图之前,我们需要了解一下画布栅格(c ...
- solrJ 基本使用
添加: PropertiesUtils pro = new PropertiesUtils();String path = pro.load("solr.properties", ...
- GSL--GNU Scientific Library 小记
摘自http://qianjigui.iteye.com/blog/847612 GSL(GNU Scientific Library)是一个 C 写成的用于科学计算的库,下面是一些相关的包 Desi ...
- noteone
- 【leetcode】1021. Best Sightseeing Pair
题目如下: Given an array A of positive integers, A[i]represents the value of the i-th sightseeing spot, ...
- exists 的简单介绍
准备数据: CREATE TABLE Books( BookID number, BookTitle VARCHAR2(20) NOT NULL, Copyright varchar2(20) ) I ...
- 安装uWebSocketIO
https://github.com/uNetworking/uWebSockets sudo apt-get install libuv1-dev git clone https://github. ...
- socket | tcp客户端 tcp服务器 udp客户端 udp 服务器 创建方法
tcp服务器 #coding=utf-8 ''' 这里是tcp服务器端,要先启动 ''' import socket import threading bind_ip = "0.0.0.0& ...