数学--数论--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 ...
随机推荐
- VAuditDemo代码审计
简介 先提一嘴,代码审计流程大概可以归结为:把握大局,定向功能,敏感函数参数回溯. 本文也是按照此思路进行,还在最后增加了漏洞修补方法. 本人平时打打CTF也有接触过代码审计,但都是零零散散的知识点. ...
- 登录窗口java
这次代码是登录窗口的制作. 主要的方面是是包括,用户名.密码.验证码.以及输入数据所需要的文本框,对于验证码可以通过点击验证码进行修改.同时对于验证码的前景色和背景色同时都得到修改. 点击注册(这里还 ...
- node+express+mysql实现简单的数据增删改查
前提 电脑已经安装了node,express,mysql. 实现步骤 1.新建数据库表 附数据表结构: 2.创建exprss项目 express -e myapp 新建一个以ejs为模板的expre ...
- GO中的channel使用小结
go关键字可以用来开启一个goroutine(协程))进行任务处理,而多个任务之间如果需要通信,就需要用到channel了. func testSimple(){ intChan := make(ch ...
- 数据结构和算法(Golang实现)(16)常见数据结构-字典
字典 我们翻阅书籍时,很多时候都要查找目录,然后定位到我们要的页数,比如我们查找某个英文单词时,会从英语字典里查看单词表目录,然后定位到词的那一页. 计算机中,也有这种需求. 一.字典 字典是存储键值 ...
- SpringCloud入门(十): Config 统一配置中心
SpringCloud Config 简介 在分布式系统中,由于服务组件过多,为了方便争对不通的环境下的服务配置文件统一管理,实时更新,所以出现了分布式配置中心组件.市面上开源的配置中心有很多,360 ...
- 天天在用Redis,持久化方案你又知道哪些?
前言 文章首发于微信公众号[码猿技术专栏]:天天用Redis,持久化方案有哪些你知道吗? Redis目前已经成为主流的内存数据库了,但是大部分人仅仅是停留在会用的阶段,你真的了解Redis内部的工作原 ...
- delphi中DateTimePicker控件同时输入日期和时间
将DateTimePicker的Format属性中加入日期格式设成 'yyyy-MM-dd HH:mm',注意大小写 , 将kind设置为dtkTime即可,可以在每次Form onShow时将Dat ...
- J - The sum problem
Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum ...
- F - Robot Motion 栈加BFS
A robot has been programmed to follow the instructions in its path. Instructions for the next direct ...