参考这篇博客: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. Android反射机制:手把手教你实现反射

    什么是反射机制? JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称 ...

  2. 伸展树的基本操作——以【NOI2004】郁闷的出纳员为例

    前两天老师讲了伸展树……虽然一个月以前自己就一直在看平衡树这一部分的书籍,也仔细地研读过伸展树地操作代码,但是就是没写过程序……(大概也是在平衡树的复杂操作和长代码面前望而生畏了)但是今天借着老师布置 ...

  3. 114. Flatten Binary Tree to Linked List -- 将二叉树转成链表(in-place单枝树)

    Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...

  4. Alpha冲刺一 (9/10)

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10034872.html 作业博客:https://edu.cnblogs.com/campus ...

  5. tornado多路由示例

    main.py代码: # encoding: utf-8 """ @version: ?? @author: andu99 @contact: andux@qq.com ...

  6. 用 Unity 和 HTC Vive 实现高级 VR 机制(1)

    原文:Advanced VR Mechanics With Unity and the HTC Vive Part 1 作者:Eric Van de Kerckhove 译者:kmyhy VR 从来没 ...

  7. Alone

    ---恢复内容开始--- 出处:皮皮bloghttp://blog.csdn.net/pipisorry/article/details/50709014 coding.net: 国内较好的代码托管平 ...

  8. c++ 读取所有图片

    copyright by Jun Yang, SUN YAT-SEN UNIVERSITY //FileList.h ///////////////////////////////////////// ...

  9. CSS布局相关概要

    一.文档流 运用css布局首先要具备一些概念上的知识,文档流的概念充斥着布局的整个过程.浏览器渲染页面是有先后顺序的,其顺序是至上而下,根据HTML的文档结构进行渲染. 二.div+css 耳熟能详的 ...

  10. UsernameToken 【转】

    原文:http://idior.cnblogs.com/articles/381534.html 使用用户名和密码来验证用户的身份是最普通也最常见的方法,虽然在安全性方面也比较弱,由于其运用的广泛性还 ...