ZR#1004

解法:

对于 $ (x^2 + y)^2 \equiv (x^2 - y)^2 + 1 \pmod p $

化简并整理得 $ 4x^2y \equiv 1 \pmod p $

即 $ 4x^2 $ 和 $ y $ 互为逆元时统计答案即可

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map> using namespace std; #define LL long long
const int N = 1e5 + 100; inline LL fast_pow(LL a,LL b,LL p) {
LL ans = 1;
while(b) {
if(b & 1) ans = ans * a % p;
a = a * a % p;
b >>= 1;
}
return ans % p;
}
map<LL,LL> vis;
LL n,p,ans,a[N]; int main() {
scanf("%lld%lld",&n,&p);
for(int i = 1 ; i <= n ; i++) {
scanf("%lld",&a[i]);
if(4 * a[i] % p * a[i] % p == 0) continue;
else vis[4 * a[i] % p * a[i] % p]++;
}
for(int i = 1 ; i <= n ; i++) {
LL inv = fast_pow(a[i],p - 2,p);
if(inv == 0) continue;
ans += vis[inv];
if(4 * a[i] % p * a[i] % p == inv) ans--;
}
printf("%lld\n",ans);
//system("pause");
return 0;
}

ZR#1004的更多相关文章

  1. bzoj 1004 Cards

    1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...

  2. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  3. 1004. Counting Leaves (30)

    1004. Counting Leaves (30)   A family hierarchy is usually presented by a pedigree tree. Your job is ...

  4. POJ做题笔记:1000,1004,1003

    1000 A+B Problem 题目大意:输入两个数a和b,输出他们的和. 代码: #include <stdio.h> int main() { int a, b; while (sc ...

  5. Shanghai Regional Online Contest 1004

    Shanghai Regional Online Contest 1004 In the ACM International Collegiate Programming Contest, each ...

  6. BZOJ 1004: [HNOI2008]Cards

    Description 给你一个序列,和m种可以使用多次的置换,用3种颜色染色,求方案数%p. Sol Burnside定理+背包. Burnside定理 \(N(G,\mathbb{C})=\fra ...

  7. PAT A 1004. Counting Leaves (30)【vector+dfs】

    题目链接:https://www.patest.cn/contests/pat-a-practise/1004 大意:输出按层次输出每层无孩子结点的个数 思路:vector存储结点,dfs遍历 #in ...

  8. [bzoj 1004][HNOI 2008]Cards(Burnside引理+DP)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 分析: 1.确定方向:肯定是组合数学问题,不是Polya就是Burnside,然后题目上 ...

  9. stack+DFS ZOJ 1004 Anagrams by Stack

    题目传送门 /* stack 容器的应用: 要求字典序升序输出,所以先搜索入栈的 然后逐个判断是否满足答案,若不满足,回溯继续搜索,输出所有符合的结果 */ #include <cstdio&g ...

随机推荐

  1. Dubbo -- 四种loadBalance负载均衡算法

    Dubbo中的一个关键接口LoadBalance,dubbo是按照其中的规则来调用多台provider的服务的. 先看一下接口的实现类图: 从上图中我们可以看到dubbo提供了四种算法来实现负载均衡. ...

  2. number与string的转换

    // number -> string // toString() /* var num = 10; var res = num.toString(); alert(typeof (num)); ...

  3. js实现图片上传本地预览

    演示地址:https://xibushijie.github.io/static/uploadImg.html <!DOCTYPE> <html> <head> & ...

  4. Python学习日记(七) 文件操作

    文件操作: 首先要有一个文件作为对象,例‘文件名’.txt 1.文件路径:例 d:\文件名.txt <1>:绝对路径:从根目录往后的路径 <2>:相对路径:当前目录下的路径有什 ...

  5. PyCharm-安装&调试

    windows安装pycharm 和python的链接: PyCharm:http://www.jetbrains.com/pycharm/ Python:https://www.python.org ...

  6. rest-assured-doc接口自动化测试,数据驱动测试平台

    原文:https://github.com/rest-assured/rest-assured/wiki/Usage 本文github地址:https://github.com/RookieTeste ...

  7. 深度学习 吴恩达深度学习课程2第三周 tensorflow实践 参数初始化的影响

    博主 撸的  该节 代码 地址 :https://github.com/LemonTree1994/machine-learning/blob/master/%E5%90%B4%E6%81%A9%E8 ...

  8. LeetCode - 82、删除排序链表中的重复元素 II

    给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4->4->5    输出: 1 ...

  9. 初学Django基础01 建立工程,目录结构,常用配置,上下文管理,模板渲染

    django是python的web重量级框架,发展已经有10年多了,对应下面版本 Django 版本 Python 版本 1.8 2.7, 3.2 , 3.3, 3.4, 3.5 1.9, 1.10 ...

  10. window10 安装mysql5.6版本

    说明:因为之前都是安装版的,我用的是5.0,版本低不能够支持现在的业务,所以升级.之前的就卸载了!!(废话太多) 下载地址:https://dev.mysql.com/downloads/file/? ...