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 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…
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 …
题意: 给一个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…
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…
Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是2.但由于n不一定是质数,我们还需要再加k条边.然后对于\(i \in [1,k]\),我们加边(i,i+n/2).当\(k\leq \frac{n}{2}\)的时候,只会把一些点的度数由2变成3,否则会出现重边问题.假设新图的边数为m,那\(m \in [n,n+\frac{n}{2}]\),如果…