参考这篇博客: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. BZOJ 3527 【ZJOI2014】 力

    题目链接:力 听说这道题是\(FFT\)板子题,于是我就来写了…… 首先可以发现这个式子:\[E_i=\sum_{j<i}\frac{q_j}{(i-j)^2}-\sum_{j>i}\fr ...

  2. Uva 12304 - 2D Geometry 110 in 1!

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. 【测试设计】性能测试工具选择:wrk?jmeter?locust?还是LR?

    原文链接:http://www.51testing.com/html/49/n-3721249.html 前言 当你想做性能测试的时候,你会选择什么样的测试工具呢?是会选择wrk?jmeter?loc ...

  4. BigDecimalUtils BigDecimal加减乘除

    public class BigDecimalUtil { private static int DEF_DIV_SCALE = 10; // 默认精确的小数位 /** * 提供精确的加法运算. * ...

  5. 99. Recover Binary Search Tree -- 找到二叉排序树中交换过位置的两个节点

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  6. Java——基本概念

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  7. Xadmin的配置及使用

    xadmin是Django的第三方扩展,可是使Django的admin站点使用更方便. 1. 安装 通过如下命令安装xadmin的最新版 pip install https://github.com/ ...

  8. Alpha阶段第1周 Scrum立会报告+燃尽图 07

    作业要求与https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246相同 一.小组介绍 组长:刘莹莹 组员:朱珅莹 孙韦男 祝玮琦 王玉潘 周 ...

  9. python实践报错:SyntaxError: Non-ASCII character

    报错: File "C:\001myWorkspace\001myWork\workspace2\MyFirstPython\src\demo4\demo4-2.py", line ...

  10. iOS-----使用GCD实现多线程

    使用GCD实现多线程 GCD的两个核心概念如下: 队列 队列负责管理开发者提交的任务,GCD队列始终以FIFO(先进先出)的方式来处理任务---但 由于任务的执行时间并不相同,因此先处理的任务并一定先 ...