题目链接

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

先将第一个二元组的两个数质因数分解一下,分解的质数加入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. js 发送短信倒计时、秒杀倒计时实现代码

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  2. Django学习笔记(3)--模板

    模板 在实际的页面大多是带样式的HTML代码,而模板是一种带有特殊语法的html文件,这个html文件可以被django编译,可以传递参数进去, 实现数据动态化.在编译完成后,生成一个普通的html文 ...

  3. python day05

    数字类型 1.整型:整数 num = 1000000000000 type(num) --->int 2.浮点型:小数 num = 123.2341 type(num) --->float ...

  4. node的第一步,hello,以及小技巧和CPU使用情况。到底能用几个核心?

    安装了啥的就不说了,百度一下有很多. Windows环境.Linux不会,所有就不说了. 1.  hello Word node的hello Word很简单,就一行. console.log(&quo ...

  5. Java BigDecimal类型的 加减乘除运算

    原文: https://blog.csdn.net/xuwei_net/article/details/81253471 加法:add 减法:subtract 乘法:multiply 除法:divid ...

  6. openstack基础框架

    openstack组件:     Computer--代码名Nova,管理VM的整个生命周期,主要职责包括启动,调度VMs,计算节点上需要至少两块网卡     Networking--代码名Neutr ...

  7. 我的工具:Ping工具

    C# Ping工具 通过该工具可以多个地点Ping服务器以检测服务器响应速度,同时也可以测试网站的响应速度,解析时间,服务器连接时间,下载速度 工具下载地址:https://download.csdn ...

  8. 基于 docker 的yapi(快速部署)

    1.使用官方的mongodb镜像 docker run --network yapi_net --ip 172.30.0.10  -d --name yapi_mongodb --restart al ...

  9. mysql union 与 union all 语法及用法

    1.mysql   union  语法 mysql   union 用于把来自多个select  语句的结果组合到一个结果集合中.语法为: select  column,......from tabl ...

  10. SpringCloud---熔断降级理解、Hystrix实战(五)

    SpringCloud---熔断降级理解.Hystrix实战(五) https://www.cnblogs.com/qdhxhz/p/9581440.html https://blog.csdn.ne ...