题目链接

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

先将第一个二元组的两个数质因数分解一下,分解的质数加入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. 中国移动能力开放商店OneNET View数据可视化公测 10分钟轻便生成行业可视化界面

    随着云计算,5G技术,人工智能等底层技术的发展,万物互联时代已经到来,同时带来了海量数据,如何效果好.低成本.短时间的表现据,成为物联网行业从业者和公司的当务之急. OneNET View传统的数据展 ...

  2. 【转】C# 定时器事件(设置时间间隔,间歇性执行某一函数,控制台程序)

    using System.Timers;定时器事件代码 static void Main(string[] args) { Method(); #region 定时器事件 Timer aTimer = ...

  3. 使用shell快速建立上万个文件夹

    #!/bin/bash#!This is a shell script to finish the folders tasks.rm -rf /home/cpay/zyc/filemkdir /hom ...

  4. springmvc上传文件错误The current request is not a multipart request

    <1>在jsp页面的<head></head>标签里面加上<meta http-equiv="Content-Type" content= ...

  5. 关于H5从PC端切换到移动端,屏幕显示内容由横向转为竖向的研究!

    1.前言: 在项目中,我们常会遇见在手机端需要横屏观看的效果,而在pc端则默认切换到竖屏的样式. 或者是,UI提供的图是一个长图,但是在移动端我们需要让这个图在手机横屏时显示. 以上两个都需要我们实行 ...

  6. python新手菜鸟之基础篇

    s=0 for i in range(1,101): s += i else: print(s) def main(n): '''打印菱形图形''' for i in range(n): print( ...

  7. git异常操作解决办法合集

    1. git add .后发现提交错误,想撤销 git reset head 文件名-----撤销某个文件 git reset head --hard 强制撤销当前的所有操作到上次提交的版本 2. g ...

  8. MonkeyRunner API简介

    MonkeyRunner工具主要有三个类: MonkeyRunner MonkeyDevice MonkeyImage 官方API文档 :http://www.android-doc.com/tool ...

  9. Python——pyqt5——消息框(QMessageBox)

    一.提供的类型 QMessageBox.information 信息框 QMessageBox.question 问答框 QMessageBox.warning 警告 QMessageBox.ctit ...

  10. linux命令(方可)

    解压:tar -xvf xxx.tar.gz 查看:rpm -qa | grep xxx卸载:rpm -e --nodeps xxx批量卸载:rpm -qa | grep xxx | xargs rp ...