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& ...
随机推荐
- POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
http://poj.org/problem?id=2262 题意: 哥德巴赫猜想,把一个数用两个奇素数表示出来. 思路:先用Eratosthenes筛法打个素数表,之后枚举即可. #include& ...
- springboot 日期类型处理
1. 日期类型输出参数处理 默认日期格式只支持:2017-07-01T10:10:01 修改为2017-07-01 10:10:01 只需要修改配置文件即可: spring: jackson: dat ...
- c++ 交换两个容器(swap)
#include <iostream> #include <vector> using namespace std; int main () { vector<,); / ...
- Builder(建造者)
意图: 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 适用性: 当创建复杂对象的算法应该独立于该对象的组成部分以及它们的装配方式时. 当构造过程必须允许被构造的对象有不同 ...
- XML_CPP_资料_libXml2_01
ZC: 看了一些 C/C++的XML文章,也看了一些 Qt的 QXmlQuery/QXmlSimpleReader/QXmlStreamReader/QXmlStreamWriter 的文章.总体感觉 ...
- [Mybatis]resultMap的使用总结
resultMap是Mybatis最强大的元素,它可以将查询到的复杂数据(比如查询到几个表中数据)映射到一个结果集当中. resultMap包含的元素的相关属性解释如下: <!--column不 ...
- UVA-1605 Building for UN (构造)
题目大意:n个国家的人要在一栋大厦里办公,要求任意两个国家的办公室要相邻(同层同边或邻层同面),设计一个满足要求的方案. 题目分析:题目限制较少,任意构造出一个解即可. 代码如下: # include ...
- 创建对象并生成结果的3个步骤-Chapter 3 P38
必须完成3个步骤才能创建对象并生成结果: 1 创建对象 namespace LanguageFeatures { public class Product { public int Product ...
- linux系统之间共享文件(CentOS6)
Server IP: 192.168.2.128 nfs, rpcbind(portmap) installed Client IP: 192.168.2.254 nfs, rpcbind(portm ...
- 发现TypeScript中同名interface接口会自动合并的特性
今天在学习怎么用TypeScript给jQuery写扩展插件时发现一个很有趣的事情