CF1025B Weakened Common Divisor 数学】的更多相关文章

Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathem…
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algorithm> #include<vector> #include<map> #in…
思路: 首先选取任意一对数(a, b),分别将a,b进行因子分解得到两个因子集合然后取并集(无需计算所有可能的因子,只需得到不同的质因子即可),之后再暴力一一枚举该集合中的元素是否满足条件. 时间复杂度:O(sqrt(amax) + n * log(amax)). 实现: #include <bits/stdc++.h> using namespace std; ; int a[MAXN], b[MAXN]; set<int> factor(int x) { set<int&…
Content 定义 \(n\) 个数对 \((a_1,b_1),(a_2,b_2),(a_3,b_3),...,(a_n,b_n)\) 的 \(\text{WCD}\) 为能够整除每个数对中至少一个数的 \(>1\) 的整数.现在,给出 \(n\) 个数对,请找出它们的 \(\text{WCD}\),或者这 \(n\) 个数对没有符合要求的 \(\text{WCD}\). 数据范围:\(1\leqslant n\leqslant 1.5\times 10^5,2\leqslant a_i,b_…
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mat…
Greatest Greatest Common Divisor Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5207 Description 在数组a中找出两个数ai,aj(i≠j),使得两者的最大公约数取到最大值. Input 多组测试数据.第一行一个数字T,表示数据组数.对于每组数据,第一行是一个数n,表示数组中元素个数,接下来一行有n个数,a1到an.1≤T≤…
题意:给你n组,每组两个数字,要你给出一个数,要求这个是每一组其中一个数的因数(非1),给出任意满足的一个数,不存在则输出-1. 思路1:刚开始乱七八糟暴力了一下果断超时,然后想到了把每组两个数相乘,然后求每组的GCD,那么这个GCD就是因数的乘积(如果GCD==1就输出-1).然后打个2e5的素筛表,然后找到GCD的一个素数因数.做到这里好像没问题了,然而,分分钟会被hack,问题出在哪里了?显然啊,打素数表只用2e5的范围,但是因数还包括自己本身啊!所以一旦GCD大于2e5我们就找不到答案了…
http://codeforces.com/problemset/problem/1025/B 大意:n对数对(ai,bi),求任意一个数满足是所有数对中至少一个数的因子(大于1) 分析: 首先求所有数对的lcm,把所有数的素因子提出来 求所有lcm的gcd,这样做求出数对之间的公共素因子gcd 注意,公共素因子可能在某一组数对中状态为某一部分是ai的素因子而剩下的一部分是bi的素因子,这种情况导致gcd既不是ai的因子又不是bi的因子,因此必须只保留下aibi公共的素因子,剔除非公共素因子,故…
题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大枚举即可,需要特判一下第一个元素是素数的情况. #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<map> #include<s…
[链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. 显然用这些质因子去试2..n就可以了. 看哪个可以满足 就输出对应的就可以了. (一开始我求出这个数的所有因子(TLE了)..其实没有必要...因为假设y是x的倍数..然后y满足的话,显然x也能满足要求..所以只要用质因子搞就行了. [代码] #include <bits/stdc++.h> #…