参考这篇博客: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的更多相关文章

  1. 【数论】【二次剩余】【map】hdu6128 Inverse of sum

    部分引用自:http://blog.csdn.net/v5zsq/article/details/77255048 所以假设方程 x^2+x+1=0 在模p意义下的解为d,则答案就是满足(ai/aj) ...

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

  3. HDU 6128 Inverse of sum(同余)

    http://acm.hdu.edu.cn/showproblem.php?pid=6128 题意:有一个a数列,并且每个数都小于p,现在要求有多少对$(i,j)$满足$\frac{1}{a_i+a_ ...

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

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

  6. NHibernate's inverse - what does it really mean?

    NHibernate's concept of 'inverse' in relationships is probably the most often discussed and misunder ...

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

  8. Codeforces 1027E Inverse Coloring 【DP】

    Codeforces 1027E Inverse Coloring 题目链接 #include<bits/stdc++.h> using namespace std; #define N ...

  9. BZOJ 3836 Codeforces 280D k-Maximum Subsequence Sum (模拟费用流、线段树)

    题目链接 (BZOJ) https://www.lydsy.com/JudgeOnline/problem.php?id=3836 (Codeforces) http://codeforces.com ...

  10. [zoj3813]Alternating Sum 公式化简,线段树

    题意:给一个长度不超过100000的原串S(只包含数字0-9),令T为将S重复若干次首尾连接后得到的新串,有两种操作:(1)修改原串S某个位置的值(2)给定L,R,询问T中L<=i<=j& ...

随机推荐

  1. c++ 计算指定半径圆的面积

    #include <iostream> #define PI 3.14 using namespace std; class Circle { float radius; public: ...

  2. python 字符串压缩

    import zlib s = b'witch which has which witches wrist watch' print(len(s)) t = zlib.compress(s) prin ...

  3. GetLastError()数字_转换为_文字

    1.具体参数 可参看 http://blog.csdn.net/hongweigg/article/details/6821536 或 其它文章 或 MSDN 2.VC6 测试代码: #include ...

  4. 动态规划-House Robber

    2018-04-29 20:20:56 House Robber问题是leetcode上经典的系列题,这里对其中的题目做一个讲解. 198. House Robber 问题描述: 问题求解: 本质上就 ...

  5. python学习笔记(locust性能测试模块)

    locust是基于python的性能测试工具.支持python2.7及其以上的版本.相对于主流的LR与Jmeter工具使用的方式不一样.locust是通过编写python代码来完成性能测试的. 通过L ...

  6. JS BOM操作

    Bom:浏览器对象模型(Browser Object Model,简称 BOM)提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口,可以对浏览器窗口进行访问和操作 (1) ...

  7. vue 表单校验 一

    表单校验 一 最近使用elment-ui表单进行各种校验,心力交瘁,依旧不能很好地解决,先列出自己的归类,后期一个个攻破 表单校验史 表单校验准则 参考资源 1 2 3 4 5 第一种 显示明确的错误 ...

  8. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  9. ViewPager + Fragment 实现主界面底部导航栏

    1. 四个类似的Frament布局 tab_main_fragment.xml <LinearLayout xmlns:android="http://schemas.android. ...

  10. Xilinx Microblaze Bootloader

    作者:Hello,Panda 一般而言,Xilinx Microblaze会被用来在系统中做一些控制类和简单接口的辅助性工作,比如运行IIC.SPI.UART之类的低速接口驱动,对FPGA逻辑功能模块 ...