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. Mac 磁盘分区格式

    Mac 磁盘分区格式 来源 https://www.chadou.me/p/190 参考文章 macOS磁盘工具帮助 在Mac系统中抹掉(格式化)磁盘的时候,要求选择分区方案,包括GUID分区图.主引 ...

  2. 分享个免费的svn平台

    平时在工作中难免会用到svn,但是要自己搭建一个,未免成本太高,近来,本人接触到一个免费的svn平台(可能大神们早就发现了),个人使用还是足够了. 地址:https://svnbucket.com 相 ...

  3. python3基础之“小练习(1)”

    (一)打印3个不同的字符 # a=int("123") # b="123" # c=1.2 # print(type(a),a) # print(type(b) ...

  4. python day 12: 选课系统

    目录 python day 12 1. 通过类来创建选课系统 1.1 类库models.py 2. 配置文件setting.py 3. administrator.py 4. student.py p ...

  5. js造成内存泄漏的几种情况

    1.介绍js的垃圾回收机制 js的垃圾回收机制就是为了防止内存泄漏的,内存泄漏的含义就是当已经不需要某块内存时这块内存还存在着,垃圾回收机制就是间歇的不定期的寻找到不再使用的变量,并释放掉它们所指向的 ...

  6. 在safari下input的placeholder设置行高失效

    在项目中遇到input的placeholder在safari下设置行高失效的问题,亲测 input{ width:250px; height:30px; line-height:30px; font- ...

  7. DRF 有无外键操作实例

    models.py from django.db import models # Create your models here. class Category(models.Model): &quo ...

  8. 关于在centos下安装python3.7.0以上版本时报错ModuleNotFoundError: No module named '_ctypes'的解决办法

    3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可. #yum install libffi-devel -y#make install若在安装前移除了/usr/bin ...

  9. K3 Cloud的数据中心加载异常处理

    以前一直是财务维护的K3  Cloud突然说不能登录,用的SQL 2008的数据库,运维也搞不定,找帮忙,因为是部署在阿里云上,上去看看数据库,这个K3数据库占了600多G,想看看这个表结构,就是打不 ...

  10. java基础(7)---IO流

    一.FileWriter 导包:import java.io.FileWriter 覆盖写入: 追加写入:  写数据换行:  write方法重载: 二.编码: 三.FileReader: read重载 ...