数学--数论--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+1aj1ai+aj≡1ai+1aj,即这两个数的和的逆元等于这两个数的逆元的和,注意0没有逆元
Input
第一行一整数TT表示用例组数,每组用例首先输入一整数nn表示序列长度和一素数pp表示模数,之后输入nn个非负整数a1,…,n(1≤T≤5,1≤n≤2×105,2≤p≤1018,0≤a1,…,n<p)a1,…,n(1≤T≤5,1≤n≤2×105,2≤p≤1018,0≤a1,…,n<p)
Output
输出满足条件的(i,j)(1≤i<j≤n)(i,j)(1≤i<j≤n)对数
Sample Input
2
5 7
1 2 3 4 5
6 7
1 2 3 4 5 6
Sample Output
4
6


最后我明白了个道理,当底数过大时,不能用普通乘法,更不不能用快速幂,因为乘一遍就爆了。于是酿成惨剧!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _m(a, p) make_pair(a, p)
map<ll, ll> mp;
map<ll, ll> mm;
ll mod;
long long ksc(long long a, long long b, long long mod)
{
long long ans = 0;
for (; b; b >>= 1){
if (b & 1)
ans = (ans + a) % mod;
a = (a + a) % mod; //(计算机加法比乘法快,a+a比a*2快)
}
return ans;
}
int main()
{
int t, n;
scanf("%d", &t);
while (t--)
{
ll cnt = 0;
mp.clear();
mm.clear();
scanf("%d %lld", &n, &mod);
for (int i = 0; i < n; i++)
{
ll a;
scanf("%lld", &a);
if (!a)
continue;
mm[a]++;
ll ans = ksc(ksc(a, a, mod), a, mod);
mp[ans]++;
}
for (auto p : mp)
{
ll cc = p.second;
cnt += cc * (cc - 1) / 2;
}
if (mod != 3)
for (auto m : mm)
{
ll n = m.second;
cnt -= n * (n - 1) / 2;
}
printf("%lld\n", cnt);
}
return 0;
}
数学--数论--HDU 6128 Inverse of sum (公式推导论)的更多相关文章
- 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 2802 F(N) 公式推导或矩阵快速幂
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...
- 数学--数论--hdu 6216 A Cubic number and A Cubic Number (公式推导)
A cubic number is the result of using a whole number in a multiplication three times. For example, 3 ...
- 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)
Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...
- 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...
- 数学--数论--HDU 5223 - GCD
Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
随机推荐
- Linux基础管理篇,软件管理程序,yum与rpm
一.RPM 一般来说,rpm类型的文件在安装的时候,会检测当前的系统是否满足当前软件需要的环境.若符合,则该软件就会被安装,并且会把软件的相关信息写入/var/lib/rpm/目录下的数据库文件中. ...
- 请设计 一个密码生成器,要求随机生成4组10位密码(C语言)
请设计 一个密码生成器,要求随机生成4组10位密码(密码只能由字母和数字组成),每一组必须包含至少一个大写字母,每组密码不能相同,输出生成的密码. #include<stdio.h> #i ...
- PHP获取当天、本周、本月、本季度、本年度时间
function get_date($date, $t = 'd', $n = 0) { if ($t == 'd') { $firstday = date('Y-m-d 00:00:00', str ...
- 2020-3-30 20175110王礼博 Exp3 免杀原理与实践
目录 1.正确使用msf编码器 2.msfvenom生成如jar之类的其他文件 3.veil 4.加壳工具 5.使用C + shellcode编程 6.使用其他课堂未介绍方法 7.通过组合应用各种技术 ...
- Python Requests-学习笔记(5)-响应状态码
我们可以检测响应状态码: r = requests.get('http://httpbin.org/get') r.status_code 为方便引用,Requests还附带了一个内置的状态码查询对象 ...
- Spring Cloud 系列之 Consul 注册中心(一)
Netflix Eureka 2.X https://github.com/Netflix/eureka/wiki 官方宣告停止开发,但其实对国内的用户影响甚小,一方面国内大都使用的是 Eureka ...
- logback日志实战
<?xml version="1.0" encoding="UTF-8" ?> <!-- <configuration> < ...
- Jmeter常用元件
1.测试计划:测试元件的容器,相当于一个项目名称 线程组: 2.监听器:负责收集测试结果,同时也被告知了结果显示的方式 (1)查看结果树:看具体某个请求——请求响应,结果明细 (2)聚合报告:汇总报 ...
- 如何初学python?资深程序员浅谈,教你学会入门python
我认为python应该是现在市面上最简单,也是最值钱的一门编程语言,所以学习的人是越来越多,但是,如何初学python?这个问题困扰着很多初学python的人,今天,给大家简单聊聊这个话题. 我曾经也 ...
- STL迭代器的使用
STL的迭代器听起来怪吓人的,其实并不是什么高深的东西,说白了就是定义了一个指向STL的指针.. 对于没个STIL都可以定义 set,,vector ,,map,,,string 定义: set< ...