You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the number of pairs of indexes (i,j)(i,j) (1≤i<j≤n1≤i<j≤n) for which (ai+aj)(a2i+a2j)≡kmodp(ai+aj)(ai2+aj2)≡kmodp. Input The first line contains integers n,p,…
数同余的个数显然是要把\(i,j\)分别放到\(\equiv\)的两边 $ (a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p $ 左右两边乘上\((a_i-a_j)\) 得:\((a_i^2-a_j^2)(a_i^2+a_j^2)\equiv a_ik-a_jk \bmod p\Longrightarrow a_i^4-a_j^4\equiv a_ik-a_jk \bmod p\Longrightarrow a_i^4-a_ik\equiv a_j^4-a_…
Count Pairs You are given a prime number pp, nn integers a1,a2,…,ana1,a2,…,an, and an integer kk. Find the number of pairs of indexes (i,j)(i,j) (1≤i<j≤n1≤i<j≤n) for which (ai+aj)(a2i+a2j)≡kmodp(ai+aj)(ai2+aj2)≡kmodp. Input The first line contains i…
Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at point (i, 0) and its radius is A[i]. Count the number of pairs of circles that have at least one common point? Input The input should be a list of n pos…
题目: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^…
题意: 给一个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_j)\ mod\ p$ 分离变量$a_i^4-ka_i\equiv (a_j^4-ka_j)\ mod\ p$ 于是就变成了常规题 代码: #include<iostream> #include<cstdio> #include<algorithm> #include&l…
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另一个的决策,则相当于我们要求方程 \(ax^3+bx^2+cx+d\equiv k\pmod{p}\) 的根,而这是很难维护的,因此这个思路行不通.考虑 \((x+y)(x^2+y^2)\) 的性质,我们考虑在前面添上一项 \((x-y)\),根据初中数学 \((x-y)(x+y)(x^2+y^2)=x^4…
传送门 可以算是纯数学题了吧... 看到这个 $(x+y)(x^2+y^2)$ 就可以想到化简三角函数时经常用到的操作,左右同乘 那么 $(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  k(a_i-a_j) \mod P$ $(a_i^2-a_j^2)(a_i^2+a_j^2)\equiv k(a_i-a_j) \mod P$ $(a_i^4-a_j^4)\equiv …
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But…
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task…