C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C Description The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest c…
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n …
http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. You are given qq queries of three types: L idid — put a book having index idid on the shelf to the left from the leftmost existing book; R idid — put…
题目链接:https://codeforces.com/contest/1370/problem/B 题意 给出 $2n$ 个数,选出 $2n - 2$ 个数,使得它们的 $gcd > 1$ . 题解 大于 $1$ 最好构造的 $gcd$ 就是 $2$ 了,根据奇偶将 $2n$ 个数分类,然后两个奇数一对,两个偶数一对即可. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >>…
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他俩乘积放回去),如果经过 k 次该操作后,能找到两个数a, b, 使得 gcd(a, b) > 1,就输出"YES",否则输出"NO" 思路 如果要使得整个数组的GCD大于 1,每个元素都必须具有一个共同的质因数,因而很容易得出 2 是最常见的质因数. 又因为偶数…
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both…
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the…
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i]之一. div2路漫漫... #include<bits/stdc++.h> using namespace std; typedef int ll; ll a[]; *]; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } map<int,int&g…
题意:有一个长度为\(2n\)的数组,删去两个元素,用剩下的元素每两两相加构造一个新数组,使得新数组所有元素的\(gcd\ne 1\).输出相加时两个数在原数组的位置. 题解:我们按照新数组所有元素均为偶数来进行构造,因为旧数组的长度为\(2n\),所以无论原数组有多少个奇数和偶数,我们都可以选择删去两个数,使得剩下的数两两组合得到偶数,直接分类讨论输出即可. 代码: #include <iostream> #include <cstdio> #include <cstrin…
题意:给你带边权的树,有\(m\)次询问,每次询问有多少点对\((u,v)\)之间简单路径上的最大边权不超过\(q_i\). 题解:真的想不到用最小生成树来写啊.... 我们对边权排序,然后再对询问的\(q_i\)排序,我们可以枚举\(q_i\),然后从last开始遍历边权,如果边权不大于\(q_i\),那么就可以用并查集将两个连通块合并且计数(因为我们是从小到大枚举的,所以将它们合并并不会对后面有影响,反而还会方便我们计数),\(cnt\)表示连通块的节点数,合并时贡献为\(res=cnt[f…