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 (公式推导论)相关推荐

  1. 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 ...

  2. 数学--数论--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 ...

  3. 数学--数论--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 ...

  4. 数学--数论--HDU 12151七夕节 Plus (因子和线性筛)

    Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...

  5. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  6. 数学--数论-- HDU 2601 An easy problem(约束和)

    Problem Description When Teddy was a child , he was always thinking about some simple math problems ...

  7. 数学--数论--Hdu 5793 A Boring Question (打表+逆元)

    There are an equation. ∑0≤k1,k2,⋯km≤n∏1⩽j<m(kj+1kj)%1000000007=? We define that (kj+1kj)=kj+1!kj! ...

  8. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  9. 数学--数论--HDU 2674 沙雕题

    WhereIsHeroFrom: Zty, what are you doing ? Zty: I want to calculate N!.. WhereIsHeroFrom: So easy! H ...

最新文章

  1. iOS-c语言小练习01
  2. ORA-01111,ORA-01110,ORA-01157报错处理
  3. Dubbo官方的Starter发布1.0.0测试版,与Spring Boot的结合将更加自然
  4. Delphi中methodaddress的代码解析
  5. QT_4_QpushButton的简单使用_对象树
  6. mysql触发器调用存储过程出错_mysql 触发器中调用存储过程
  7. Nginx的原理解析
  8. 扩展中断控制器8259实验_「正点原子FPGA连载」第十三章双核AMP实验
  9. 基于RStudio 实现数据可视化之二
  10. .Net更改代码生成不生效
  11. 编程基本功:代码都写不好,还写什么注释
  12. Java常用集合类详解
  13. 百度编辑器ueditor 的 submit 表单提交
  14. 国际计算机科学期刊,学术|16个国际顶尖计算机期刊介绍与作者教程
  15. 机器学习笔记(九)——数据降维:主成分分析法(PCA)
  16. 正式通知!低学历恭喜了!每人补贴8000元,限本科以下学历,政策扶持,名额有限,速看...
  17. xposed android debug,Android 手机开启全局调试xposed插件
  18. 《人工智能——从小白到大神》,张亚勤院士与百度陈尚义理事长联袂推荐
  19. 斐波那契数列前20项及和
  20. r ridge回归_手把手带你画高大上的lasso回归模型图

热门文章

  1. C++11之std::async使用介绍
  2. java颜色gui_Java gui颜色不加载
  3. site_url()和base_url()
  4. 挪车+php,还在苦苦寻找占你车位的人?关注这个微信号实现“一键挪车”
  5. ldap配置系列二:jenkins集成ldap
  6. 从测试角度对测试驱动开发的思考【转】
  7. protobuf oc
  8. Comparable和Comparator的区别
  9. 发现以前的一些记录 shutdown AP CPU
  10. 截取最后一个下划线前面的字符