cf 990G - GCD Counting】的更多相关文章

题意 #include<bits/stdc++.h> #define t 200000 #define MAXN 200100 using namespace std; int n; int fa[MAXN],fa1[MAXN]; long long ans[MAXN],size[MAXN]; vector <int> e[MAXN],Edge[MAXN]; int find(int x){ if (x==fa1[x]) return fa1[x]; else return fa1…
Discription You are given a tree consisting of nn vertices. A number is written on each vertex; the number on vertex ii is equal to aiai. Let's denote the function g(x,y)g(x,y) as the greatest common divisor of the numbers written on the vertices bel…
CF EDU 1101D GCD Counting 题意 有一颗树,每个节点有一个值,问树上最长链的长度,要求链上的每个节点的GCD值大于1. 思路 由于每个数的质因子很少,题目的数据200000<2*3*5*7*11*13*17=510510.所以每个节点的质因子个数不多.那么树形DP的时候直接枚举每种因子即可. //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") /…
题目地址:CF1101D GCD Counting zz的我比赛时以为是树剖或者点分治然后果断放弃了 这道题不能顺着做,而应该从答案入手反着想 由于一个数的质因子实在太少了,因此首先找到每个点的点权的所有质因子 进行一次树形dp,每次更新暴力枚举所有质因子即可 代码: #include <bits/stdc++.h> using namespace std; const int N = 200006; int n, ans = 1; vector<int> p[N], c[N],…
G - GCD Counting 思路:我猜测了一下gcd的个数不会很多,然后我就用dfs回溯的时候用map暴力合并就好啦. 终判被卡了MLE.....  需要每次清空一下子树的map... #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int,int> #define piii pair<…
https://www.luogu.org/problemnew/show/CF990G 耶,又一道好题被我浪费掉了,不会做.. 显然可以反演,在这之前只需对于每个i,统计出有多少(x,y),满足x到y简单路径上所有点权值都是i的倍数即可 方法1: 可以发现,对于给定的i,这样的“权值是i的倍数”的点一定可以构成一些连通块,每个连通块内部的点两两符合条件,且不会出现跨连通块的合法点对 自己的做法: 那么,搞2*10^5个动态开点的并查集,对于每条边(u,v),枚举所有a[u]和a[v]的公因子i…
几个月的坑终于补了…… 题目链接:CF原网  洛谷 题目大意:一棵 $n$ 个点的树,每个点有点权 $a_i$.一条路径的长度定义为该路径经过的点数.一条路径的权值定义为该路径经过所有点的点权的 GCD.问所有权值不为 $1$ 的路径中,最长的长度. $1\le n\le 2\times 10^5,1\le a_i\le 2\times 10^5$. 我可能是数据结构学傻了,一眼点分治……然后复杂度又不对…… 正解:我们发现只要 $\gcd$ 不为 $1$ 就行了,而两个数的 $\gcd$ 不为…
H. Path Counting time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output You are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y…
You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to ai . Let's denote the function g(x,y) as the greatest common divisor of the numbers written on the vertices belonging to the simple…
传送门 简单的中国剩余定理练习. 首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了. 我们可以得到线性模方程组: $y \equiv 0 \pmod{a_1}$ $y+1 \equiv 0 \pmod {a_2}$ $y+2 \equiv 0 \pmod {a_3}$ $...$ $y+n \equiv 0 \pmod {a_{n+1}}$ 然后CRT搞出来一组解,暴力判判就OK了. //CF338D //by Cydiater //2017.2.20 #include &l…