ZR#1004
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的更多相关文章
- bzoj 1004 Cards
1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...
- 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 ...
- 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- POJ做题笔记:1000,1004,1003
1000 A+B Problem 题目大意:输入两个数a和b,输出他们的和. 代码: #include <stdio.h> int main() { int a, b; while (sc ...
- Shanghai Regional Online Contest 1004
Shanghai Regional Online Contest 1004 In the ACM International Collegiate Programming Contest, each ...
- BZOJ 1004: [HNOI2008]Cards
Description 给你一个序列,和m种可以使用多次的置换,用3种颜色染色,求方案数%p. Sol Burnside定理+背包. Burnside定理 \(N(G,\mathbb{C})=\fra ...
- PAT A 1004. Counting Leaves (30)【vector+dfs】
题目链接:https://www.patest.cn/contests/pat-a-practise/1004 大意:输出按层次输出每层无孩子结点的个数 思路:vector存储结点,dfs遍历 #in ...
- [bzoj 1004][HNOI 2008]Cards(Burnside引理+DP)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1004 分析: 1.确定方向:肯定是组合数学问题,不是Polya就是Burnside,然后题目上 ...
- stack+DFS ZOJ 1004 Anagrams by Stack
题目传送门 /* stack 容器的应用: 要求字典序升序输出,所以先搜索入栈的 然后逐个判断是否满足答案,若不满足,回溯继续搜索,输出所有符合的结果 */ #include <cstdio&g ...
随机推荐
- redux的理解
Redux 这里介绍下我对Redux的理解,不涉及如何使用Redux. Redux 官网介绍: A predictable state container for JavaScript apps.(一 ...
- c#使用正则表达式处理字符串
正则表达式可以灵活而高效的处理文本,可以通过匹配快速分析大量的文本找到特定的字符串. 可以验证字符串是否符合某种预定义的格式,可以提取,编辑,替换或删除文本子字符串. 现在如下特定的字符串: stri ...
- typescript_类
//类的定义 class Animal{ id:string;//默认访问修饰符为 public : 类本身.子类.类外部可访问 public name:string; // public : 类本身 ...
- Linux下MySQL的数据文件存放在哪里的??
http://bbs.csdn.net/topics/390620630 mysql> show variables like '%dir%';+------------------------ ...
- Linux 曝出严重安全漏洞,受限用户亦可提权至 Root 身份运行任意命令!(内附解决方案)
本文首发于:微信公众号「运维之美」,公众号 ID:Hi-Linux. 「运维之美」是一个有情怀.有态度,专注于 Linux 运维相关技术文章分享的公众号.公众号致力于为广大运维工作者分享各类技术文章和 ...
- python高级特性-生成器
在python中一边循环一边计算的机制成为生成器(generator) 在每次调用next()的时候执行,遇到yield语句返回,再次执行时从上次返回的yield语句处继续执行. 生成list > ...
- 使用 create-react-app 快速构建 React 开发环境
在终端执行以下命令创建项目: 1.指定创建的项目位置(这里以桌面为例) cd Desktop 2.创建 React 项目 npx create-react-app my-app 3.进入项目并启动 c ...
- Oracle数据库使用游标查询结果集所有数据
--Oracle使用游标查询结果集所有数据 DECLARE myTabelName NVARCHAR2():=''; --表名 myTableRowComment NVARCHAR2():=''; - ...
- 零基础python教程—python数组
在学习Python过程中数组是个逃不过去的一个关,既然逃不过去咱就勇敢面对它,学习一下python中数组如何使用. 1.数组定义和赋值 python定义一个数组很简单,直接 arr = [];就可以了 ...
- 题解 洛谷P2258 【子矩阵】
应该很容易想到暴力骗分. 我们考虑暴力\(dfs\)枚举所有行的选择,列的选择,每次跑一遍记下分值即可. 时间复杂度:\(O(C_n^r \times C_m^c \times r \times c) ...