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 belonging to th…
题目地址: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],…
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221 Accepted Submission(s): 58 Problem Description This is a simple problem. The teacher gives Bob a list of probl…
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<…
树状数组... Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1541 Accepted Submission(s): 599 Problem Description This is a simple problem. The teacher gives Bob a lis…