HDU6128-Inverse of sum
参考这篇博客:https://blog.csdn.net/dormousenone/article/details/77340852
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAXN 100010
LL a[MAXN], n, p;
LL calc(){
LL res = ;
a[n] = -;
, cnt = ;i <= n;++i){
])cnt++;
else{
res += LL(cnt - ) * cnt / ;
cnt = ;
}
}
return res;
}
LL qmult(LL x, LL y){
LL res = ;
if(x < y)swap(x, y);
while(y){
)res = (res + x) % p;
x = (x << ) % p;
y >>= ;
}
return res;
}
int main(){
int T;
scanf("%d", &T);
while(T--){
scanf("%I64d%I64d", &n, &p);
;i < n;++i)scanf("%I64d", a + i);
){
, cnt2 = ;
;i < n;++i){
)cnt1++;
) cnt2++;
}
LL ans = LL(cnt1 - ) * cnt1 / + LL(cnt2 - ) * cnt2 / ;
cout << ans << endl;
}else{
sort(a, a + n);
LL ans = -calc();
;i < n;++i)a[i] = qmult(a[i], qmult(a[i], a[i]));
sort(a, a + n);
ans += calc();
cout << ans << endl;
}
}
;
}
HDU6128-Inverse of sum的更多相关文章
- 【数论】【二次剩余】【map】hdu6128 Inverse of sum
部分引用自:http://blog.csdn.net/v5zsq/article/details/77255048 所以假设方程 x^2+x+1=0 在模p意义下的解为d,则答案就是满足(ai/aj) ...
- 2017ACM暑期多校联合训练 - Team 7 1009 HDU 6128 Inverse of sum (数学计算)
题目链接 Problem Description There are n nonnegative integers a1-n which are less than p. HazelFan wants ...
- HDU 6128 Inverse of sum(同余)
http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:有一个a数列,并且每个数都小于p,现在要求有多少对$(i,j)$满足$\frac{1}{a_i+a_ ...
- 2017多校第7场 HDU 6128 Inverse of sum 推公式或者二次剩余
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:给你n个数,问你有多少对i,j,满足i<j,并且1/(ai+aj)=1/ai+1/a ...
- 数学--数论--HDU 6128 Inverse of sum (公式推导论)
Description 给nn个小于pp的非负整数a1,-,na1,-,n,问有多少对(i,j)(1≤i<j≤n)(i,j)(1≤i<j≤n)模pp在意义下满足1ai+aj≡1ai+1aj ...
- NHibernate's inverse - what does it really mean?
NHibernate's concept of 'inverse' in relationships is probably the most often discussed and misunder ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- Codeforces 1027E Inverse Coloring 【DP】
Codeforces 1027E Inverse Coloring 题目链接 #include<bits/stdc++.h> using namespace std; #define N ...
- BZOJ 3836 Codeforces 280D k-Maximum Subsequence Sum (模拟费用流、线段树)
题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=3836 (Codeforces) http://codeforces.com ...
- [zoj3813]Alternating Sum 公式化简,线段树
题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...
随机推荐
- JAVA基础之复识一
JAVA不单是一门计算机编程语言,而且还是一种基于WEB的全方位软件开发技术, java特定运行平台及关键特点 java开发工具包的安装,配置与应用 java语言的基本概念 java面向对象编程 ja ...
- lua劈分字符串方法及实例
由于工作项目需要,最近需要用lua来写一些脚本.然而lua并不想java那样有很多的好用的api,很多方法得我们自己来编写和封装,就比如今天碰到的劈分字符串,查找资料后只能自己写了一个. 代码如下 - ...
- find ... -exec ... {} \; 的解释
find的特殊功能是能够进行额外的动作,如上图的 find / -type f -name "test.txt" -exec rm {} \;命令 1) {} 代表的是由find找 ...
- tomcat 容器下web项目由http改为https操作步骤及相关的坑
一.https介绍: HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP ...
- Django rest framework源码分析(一) 认证
一.基础 最近正好有机会去写一些可视化的东西,就想着前后端分离,想使用django rest framework写一些,顺便复习一下django rest framework的知识,只是顺便哦,好吧. ...
- HTTP相关知识点
一.工作原理 HTTP协议工作于客户端-服务器架构上.浏览器作为HTTP客户端通过URL向HTTP服务端(即web服务端)发送所有请求. Web服务器接收到请求后,向客户端发送相应的响应信 ...
- java基础第6天
面向对象 当需求单一,或者简单时,我们一步一步去操作没问题,并且效率也挺高.可随着需求的更改,功能的增多,发现需要面对每一个步骤很麻烦了,这时就开始改进,能不能把这些步骤和功能再进行封装,封装时根据不 ...
- MVC项目使用Oracle数据库运行提示:找不到请求的 .Net Framework Data Provider。可能没有安装
MVC项目使用Entity Framework针对Oracle数据库进行开发时,由于Oracle官方网站一般建议开发者在64位操作系统中使用32位ODP.Net进行开发.在进行程序编码的时候不会有问题 ...
- L202
Yuan Cao’s teenage years were hardly typical. By age 18, he had already graduated from high school, ...
- New Concept English Two 16 40
Keynote Speech are useful. $课文38 唯独没有考虑到天气 388. My old friend, Harrison, had lived in the Mediterr ...