【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]
【题解】
求出第一个数对的两个数他们有哪些质因子。
显然用这些质因子去试2..n就可以了。
看哪个可以满足 就输出对应的就可以了。
(一开始我求出这个数的所有因子(TLE了)。。其实没有必要。。。因为假设y是x的倍数。。然后y满足的话,显然x也能满足要求。。所以只要用质因子搞就行了。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 15e4;
int n,m;
int a[N+10][2];
set<int> myset;
vector<int> v;
void get_yinzi(int x){
int len = sqrt(x);
for (int i = 1;i <= len;i++){
if (x%i==0) {
myset.insert(i);
while (x%i==0 && i!=1 ) x/=i;
}
}
if (x>1) myset.insert(x);
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d",&n);
for (int i = 1;i <= n;i++) scanf("%d%d",&a[i][0],&a[i][1]);
for (int i = 0;i <=1;i++) get_yinzi(a[1][i]);
for (int x:myset) v.push_back(x);
m=v.size();
for (int i = 0;i < m;i++){
int x = v[i];
if (x<=1) continue;
bool ok = true;
for (int j = 2;j <= n;j++){
if ((a[j][0]%x==0) || (a[j][1]%x==0)){
continue;
}else {
ok = false;
break;
}
}
if (ok){
printf("%d\n",x);
return 0;
}
}
puts("-1");
return 0;
}
【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor的更多相关文章
- 【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 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) B. Weakened Common Divis
题目链接 让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除. 先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对 ...
- 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同样很显然 性 ...
- 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 ...
随机推荐
- Coco2d-js/Cocos2d-html5中Android返回键实现
导语: 首先Cocos2d-x其中实现Menu和Back按键相对简单一点,而在资源较少的Cocos2d-html5其中.要实现返回还是有一点不一样的,并且有没有详细的demo.也就仅仅有自己去看api ...
- 关于jetty服务器默认首页和端口设置
一.jetty服务器部署.启动成功后,在浏览器输入http://localhost:8080/ 可以直接访问到jetty欢迎首页. 这是因为在Jetty包中默认带了一个test.war的应用,在${J ...
- class com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text
运行mapreduce遇到的错: Java.lang.ClassCastException: classcom.sun.jersey.core.impl.provider.entity.XMLJAXB ...
- Getting started with ASP.NET Core MVC and Visual Studio
This tutorial will teach you the basics of building an ASP.NET Core MVC web app using Visual Studio ...
- [POJ 3621] Sightseeing Cows
[题目链接] http://poj.org/problem?id=3621 [算法] 01分数规划(最优比率环) [代码] #include <algorithm> #include &l ...
- python笔记:文件操作
1.逐行打印整个文件 # -*- coding: utf-8 -*- f = open("test",'r',encoding="utf-8") count = ...
- Linux Shell Scripting Cookbook 读书笔记 4
正则, grep 1. 正则表达式 正则表达式 描述 示例 ^ 行起始标记 ^hell匹配以hell开头的行 $ 行尾标记 test$匹配以test结尾的行 . 匹配任意一个字符 hell ...
- Oracle获取alter.log的方法
10g下:可以在 admin\{sid}\pfile文件下的init.ora文件中找到以下内容:audit_file_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\ORC ...
- 在AndroidManifest(清单文件)中注册activity(活动)及配置主活动、更改App图标、App名称、修改隐藏标题栏
打开app/src/main/AndroidManifest. <?xml version="1.0" encoding="utf-8"?> < ...
- Android 消息队列机制
在非UI线程使用Handler进行线程通信时,一般都需要进行3个步骤: 创建Looper Looper.prepar() 创建Handler 启动消息循环Looper.loop() 通过这3步,基本就 ...