Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis
让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除。
先将第一个二元组的两个数质因数分解一下,分解的质数加入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的更多相关文章
- 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 ...
- 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( ...
- 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 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra
问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw 操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解
真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】
[链接] 我是链接,点我呀:) [题意] 给你一个字符串s. 让你在其中的某一些位置进行操作.. 把[1..i]和[i+1..n]翻转. 使得里面01交替出现的那种子串的长度最长. [题解] 可以用a ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
[链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...
- 【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] [题解] 求出第一个数对的两个数他们有哪些质因子. ...
- 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 ...
随机推荐
- WIN10REALTEL高清音频管理器如何调音?调音无效怎么办?
从win7升级到win10,发现realtel高清音频管理器不能调节高级音响效果了,即使设置也没用. 经过研究后发现是驱动 问题,不是驱动 没有安装,而是可能 没有安装完整,于是下载了驱动精灵,重新安 ...
- Linux云计算工程师
一.Linux运维基础 二.Linux运维高级-核心知识提高 三.50台集群实战 四.200-1000台集群实战 五.shell编程企业级实战 六.数据库MySQL和NoSQL 七.LVM虚拟化和机房 ...
- P1551 亲戚题解
标准并查集板子题 没啥好说的,分明是白书上的(除了输入方式外一点都没改动) #include<cstdio> #include<iostream> using namespac ...
- 特殊需求:EF 6.x如何比较TimeSpan格式的字符串?EF Core实现方式是否和EF 6.x等同?
前言 我们知道C#中的TimeSpan对应SQL Server数据库中的Time类型,但是如果因为特殊需求数据库存储的不是Time类型,而是作为字符串,那么我们如何在查询数据时对数据库所存储的字符串类 ...
- python中的线程技术
#!/user/bin/env python # @Time :2018/7/7 11:42 # @Author :PGIDYSQ #@File :DaemonTest.py import threa ...
- rpm安装查看卸载软件
1.安装 rpm -i 需要安装的包文件名 举例如下: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rpm 安装 example.rpm ...
- 软工+C(4): Alpha/Beta换人
// 上一篇:超链接 // 下一篇:工具和结构化 注:在一次软件工程讨论课程进度设计的过程中,出现了这个关于 Alpha/Beta换人机制的讨论,这个机制在不同学校有不同的实施,本篇积累各方观点,持续 ...
- Vue中的状态管理器 - Vuex
我们知道vue是组件式开发的,当你的项目越来越大后,每个组件背后的数据也会变得越来越难以理顺, 这个时候你就可以考虑使用vuex了. 备注: 官方建议小项目不要使用,引入vuex会带来新的概念和模式, ...
- 获取SQL数据库中的数据库名、所有表名、所有字段名、列描述
1.获取所有数据库名: (1).Select Name FROM Master.dbo.SysDatabases orDER BY Name 2.获取所有表名: (1).Select Na ...
- MT【325】垂心的向量形式
设$H$为垂心,且$3\overrightarrow{HA}+4\overrightarrow {HB}+5\overrightarrow {HC}=\overrightarrow 0$,则$\cos ...