题目链接

让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除。

先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对s中的质数进行判断是否能整除。如果某个质数可以被n-1个二元组整除(两个数中的一个)。

好浅显的思路,,,可是我就是没想到,,,哭辽,xyqnb mdhnb fyznb %大佬

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N =2e5+32;
int n;
LL ans;
struct uzi
{
int a,b;
}p[N];
int a[N],Q[N],cnt;
void P(){
for(int i=2;i<N;i++){
if(!Q[i])a[++cnt]=i;
for(int j=1;j<=cnt&&1ll*a[j]*i<N;j++){
Q[a[j]*i]=1;
if(i%a[j]==0)break;
}
}
}
set<int>s,t;
map<int,int>vis;
int main(){
ios::sync_with_stdio(false);
P();
cin>>n;
for(int i=1;i<=n;i++)cin>>p[i].a>>p[i].b;
for(int i=1;i<=cnt&&1ll*a[i]*a[i]<=p[1].a;i++){
if(p[1].a%a[i]==0){
while(p[1].a%a[i]==0)p[1].a/=a[i];
s.insert(a[i]);
}
}
for(int i=1;i<=cnt&&1ll*a[i]*a[i]<=p[1].b;i++){
if(p[1].b%a[i]==0){
while(p[1].b%a[i]==0)p[1].b/=a[i];
s.insert(a[i]);
}
}
if(p[1].a>1)s.insert(p[1].a);
if(p[1].b>1)s.insert(p[1].b);
for(int i=2;i<=n;i++){
for(auto k:s){
if(p[i].a%k==0||p[i].b%k==0)vis[k]++;
if(vis[k]==n-1)return cout<<k,0;
}
}
for(auto k:s)if(vis[k]==n-1)return cout<<k,0;
return cout<<-1,0;
}

Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis的更多相关文章

  1. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)

    B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...

  2. D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...

  3. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    A : A. Doggo Recoloring time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra

    问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw  操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...

  5. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解

    真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...

  6. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】

    [链接] 我是链接,点我呀:) [题意] 给你一个字符串s. 让你在其中的某一些位置进行操作.. 把[1..i]和[i+1..n]翻转. 使得里面01交替出现的那种子串的长度最长. [题解] 可以用a ...

  7. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring

    [链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...

  8. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor

    [链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. ...

  9. E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...

随机推荐

  1. 数据库MySQL和Redis实践

    1.关于数据库设计的那些事 2.MySQL 3.Redis

  2. Mybatis 批量添加,批量更新

    此篇适合有一定的mybatis使用经验的人阅读. 一.批量更新 为了提升操作数据的效率,第一想到的是做批量操作,直接上批量更新代码: <update id="updateBatchMe ...

  3. nginx 常见正则匹配符号表示

    1.^: 匹配字符串的开始位置: 2. $:匹配字符串的结束位置: 3..*: .匹配任意字符,*匹配数量0到正无穷: 4.\. 斜杠用来转义,\.匹配 . 特殊使用方法,记住记性了: 5.(值1|值 ...

  4. Effective C++ 第0章 copy constructor和copy assignment operator

    拷贝构造函数(copy constructor)被用来以一个对象来初始化同类型的另一个对象,拷贝赋值运算符(copy assignment operator)被用来将一个对象中的值拷贝到同类型的另一个 ...

  5. django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?

    Error msg: Unhandled exception in thread started by <function check_errors.<locals>.wrapper ...

  6. hibernate 查询字段是重复名字的处理方法

    目前遇到了三种情况: 一:当表的字段是数字类型(int,long .....) select name,ifnull(conpih.uh_id,0) from user; 将重复的字段如上修改用ifn ...

  7. SQL操作符、通配符等

    一.通配符 常用模糊查询:% SELECT * FROM TB_Name WHERE FIELD LIKE pattern   SELECT * FROM Persons WHERE name LIK ...

  8. 【刷题】Git工作流-相关知识点

    参考资料:[学习总结]Git学习-GIT工作流-千峰教育(来自B站) 1-Git工作流 GitFlow流五大分支: 主干分支 热修复分支 预发布分支 开发分支 功能分支 GitFlow 工作流定义了一 ...

  9. iTextCharp c#

    //引用iTextSharp static void testPdf() { var document = new Document(); var writer = PdfWriter.GetInst ...

  10. MySQL select into outfile 和 load data infile数据跨库转移

    select into outfile用法 SELECT ... FROM TABLE_A INTO OUTFILE "/path/to/file" FIELDS TERMINAT ...