数学--数论--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被当矿机排查案例
1.发现服务器变的特别卡,正常服务运行很慢. 到服务器上查询一番发现top下发现 bashd的进程占用100%CPU了. find /-name bashd* //第一次查询文件占用目录kil ...
- C语言 刷新缓冲区
fflush int fflush(FILE* stream); 用于清空文件缓冲区,如果文件是以写的方式打开 的,则把缓冲区内容写入文件. eg: 1. #include <stdio.h&g ...
- C语言 文件操作(二)
1.fputc(); fputc 是 file output char 的所以,意思是向指定的文件中写入一个字符.fputc() 的用法为: int fputc ( int ch, FILE *fp ...
- 统计分析_集中趋势and离散程度
1.数组的集中趋势-如何定义数组的中心 1.1 常用几下几个指标来描述一个数组的集中趋势 均值-算术平均数 . 中位数-将数组升序或降序排列后,位于中间的数. 众数-数组中出现最多的数. 1.2 指标 ...
- 36 Thread 多线程
/* * 多线程的实现方式: * 方式1:一种方法是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 * * Thread * Str ...
- C语言变长数组
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Variable ...
- phoenix 索引实践
准备工作 创建测试表 CREATE TABLE my_table ( rowkey VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 V ...
- vue中的错误日志
一.Error compiling template: Component template requires a root element, rather than just text. 这个错误意 ...
- 使用dynamic和MEF实现轻量级的AOP组件 (3)
转摘 https://www.cnblogs.com/niceWk/archive/2010/07/22/1783068.html 水到渠成 在上一篇的<偷梁换柱>中,介绍了Weavabl ...
- 使用dynamic和MEF实现轻量级的AOP组件 (2)
转摘 https://www.cnblogs.com/niceWk/archive/2010/07/21/1782092.html 偷梁换柱 上一篇我们初试了DynamicAspect这把小刀,如果你 ...