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 ...
随机推荐
- Flutter:教你用CustomPaint画一个自定义的CircleProgressBar
https://www.jianshu.com/p/2ea01ae02ffe Flutter:教你用CustomPaint画一个自定义的CircleProgressBar paint_page.dar ...
- C++ | 使用const std::map,map::[]时遇到的一个bug
原函数简化后如下: void fun(const map<int,vector<int>> &mp, int index) { for (auto tmp : mp[i ...
- 常用的js加密
https://github.com/hellobajie/AES-of-JavaScript 此为js的 AES加密方式,两个加密文档,可当做扣js必备
- PAT-2019年冬季考试-乙级(题解)
很荣幸这次能够参加乙级考试,和大佬们同台竞技了一次,这篇博客,进行介绍这次2019冬季的乙级考试题解. 7-1 2019数列 (15分) 把 2019 各个数位上的数字 2.0.1.9 作为一个数列的 ...
- vue 关于props 父组件传值
swiper.vue 子组件 info.vue 父组件 swiper.vue<template> <div class="swiper-wrap" @mouse ...
- python __main__ 里的变量是全局变量 因此在函数里面可以访问到
__main__ and scoping in python from:https://stackoverflow.com/questions/4775579/main-and-scoping-in- ...
- 《hello-world》第九次团队作业:【Beta】Scrum meeting 3
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目验收 团队名称 <hello--wor ...
- 「NOI2016」循环之美
P1587 [NOI2016]循环之美 题目描述 牛牛是一个热爱算法设计的高中生.在他设计的算法中,常常会使用带小数的数进行计算.牛牛认为,如果在 $k$ 进制下,一个数的小数部分是纯循环的,那么它就 ...
- MyEclipse激活代码
package TestCase; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...
- ASP.NET MVC 5 入门-2控制器、路由
一.创建项目: 上起始页,选择新项目. 在中新的项目对话框中,右侧语言类别选择C# ,然后项目类型选择Web,然后选择ASP.NET Web 应用程序 (.NET Framework) 项目模板. 将 ...