题目http://codeforces.com/contest/1189/problem/E

题意:给定$n$个互不相同数,一个$k$和一个质数$p$。问这$n$个数中有多少对数$(a_i+a_j)(a_i^2+a_j^2)\equiv k\,mod\,p$

思路:这一场的题目好像都很思维啊,代码量不多,想得出来就能写。

同余式左右两边同乘一个非零的数同余式不变,所以原式可以变为

$(a_i-a_j)(a_i+a_j)(a_i^2+a_j^2)\equiv (a_i-a_j)k = (a_i^2-a_j^2)(a_i^2+a_j^2)\equiv (a_i-a_j)k = (a_i^4-a_j^4)\equiv a_ik-a_jk = a_i^4 - a_ik \equiv a_j^4 - a_jk$

所以对于每一个数我们只需要计算$a_i^4-a_ik\,mod\,p$,然后根据这个能取到这个值的集合大小来计算答案就行了。

 #include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<iostream> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pr; int n, p, k;
const int maxn = 3e5 + ;
int num[maxn];
map<int, int>mp; int main()
{
scanf("%d%d%d", &n, &p, &k);
for(int i = ; i < n; i++){
scanf("%d", &num[i]);
int res = ((LL)num[i] * num[i] % p * num[i] % p - k) % p * num[i] % p;
res = (res + p) % p;
if(mp.find(res) != mp.end()){
mp[res] = mp[res] + ;
}
else{
mp[res] = ;
}
}
map<int, int>::iterator iter;
int ans = ;
for(iter = mp.begin(); iter != mp.end(); iter++){
int x = iter->second;
//cout<<iter->first<<":"<<iter->second<<endl;
ans += x * (x - ) / ;
}
printf("%d\n", ans);
return ;
}

codeforces#572Div2 E---Count Pairs【数学】【同余】的更多相关文章

  1. CodeForces - 1189 E.Count Pairs (数学)

    You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the numbe ...

  2. CF1188B/E Count Pairs(数学)

    数同余的个数显然是要把\(i,j\)分别放到\(\equiv\)的两边 $ (a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p $ 左右两边乘上\((a_i-a_j ...

  3. CodeForces - 1189E Count Pairs(平方差)

    Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Fi ...

  4. [MeetCoder] Count Pairs

    Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at po ...

  5. Codeforces 1188B Count Pairs (同余+分离变量)

    题意: 给一个3e5的数组,求(i,j)对数,使得$(a_i+a_j)(a_i^2+a_j^2)\equiv k\ mod\ p$ 思路: 化简$(a_i^4-a_j^4)\equiv k(a_i-a ...

  6. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

  7. Codeforces 1189E. Count Pairs

    传送门 可以算是纯数学题了吧... 看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘 那么 $(a_i+a_j)(a_i^2+a_j^2) \equiv  ...

  8. Codeforces 839C Journey - 树形动态规划 - 数学期望

    There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...

  9. codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)

    题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. LocalDate LocalTime LocalDateTime Instant的操作与使用

    一.简介 LocalDate表示当前(或指定)日期,格式为:yyyy-MM-dd LocalTime表示当前(或指定)时间,格式为:HH:mm:ss SSS LocalDateTime表示当前(或指定 ...

  2. Python25之字典1

    一.字典的意义 字典不同于前述的序列类型,他是一种映射类型,它的引入就是为了简化定义索引值和元素值存在的特定关系的定义和访问问题 二,字典定义 字典变量名 = {key1 : value1, key2 ...

  3. FZU2018级算法第五次作业 m_sort(归并排序或线段树求逆序对)

    首先对某人在未经冰少允许情况下登录冰少账号原模原样复制其代码并且直接提交的赤裸裸剽窃行为,并且最终被评为优秀作业提出抗议! 题目大意: 给一个数组含n个数(1<=n<=5e5),求使用冒泡 ...

  4. closed channel

    func Test_chanel(t *testing.T) { c := make(chan int, 1) go func() { time.Sleep(time.Second * 3) clos ...

  5. Codeforces Round #588 (Div. 1) 简要题解

    1. 1229A Marcin and Training Camp 大意: 给定$n$个对$(a_i,b_i)$, 要求选出一个集合, 使得不存在一个元素好于集合中其他所有元素. 若$a_i$的二进制 ...

  6. swift 有哪些学习资源

    Swift有哪些优秀的学习资源呢? 首先要推荐的当然是官方的资料了. 这个地址里放的是苹果官方为开发者提供的Swfit学习资源:https://developer.apple.com/swift/re ...

  7. JS 页面刷新以及页面返回的几种方式

    1.通过标签形式的跳转页面  <a class="popup" href="~/WeiXin/Shoppingguide/StockData">&l ...

  8. 让image居中对齐,网页自适应

    <div class="page4_content"> <div class="page4_box"> <div class=&q ...

  9. 链接标签<a>去掉下划线

    1.去掉下划线 text-decoration:none:

  10. javascript中bind()、call()、apply()的使用

    一直以来对bind().apply().call()这三个方法都模模糊糊的,现在有时间详细的看看这三个方法,并记录下来. bind() 参考文档:https://developer.mozilla.o ...