codeforces 1025B Weakened Common Divisor(质因数分解)
题意:
给你n对数,求一个数,可以让他整除每一对数的其中一个
思路:
枚举第一对数的质因数,然后暴力
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e7+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); inline int read(){
int num;
char ch;
while((ch=getchar())<'' || ch>'');
num=ch-'';
while((ch=getchar())>='' && ch<=''){
num=num*+ch-'';
}
return num;
}
int c = ;
int p[maxn];
void d(int x){
for(int i=;1ll*i*i<=x;i++)if(x%i==){
p[c++]=i;
while(x%i==)x/=i;
}
if(x>)p[c++]=x;
}
ll gcd(ll a, ll b){
return b == ? a : gcd(b, a % b);
}
PLL pa[ + ];
bool cmp(PLL a, PLL b){
return max(a.fst, a.sc) < max(b.fst, b.sc);
}
int main() {
int n;
scanf("%d", &n); for(int i = ; i < n; i++){
scanf("%I64d %I64d", &pa[i].fst, &pa[i].sc);
}
//sort(pa, pa+n, cmp);
d(pa[].fst);
d(pa[].sc);
if(n==){
printf("%I64d", pa[].fst);
return ;
}
for(int i = ; i < c; i++){
int flg = ;
for(int j = ; j < n && flg; j++){
if(pa[j].fst%p[i]!= && pa[j].sc%p[i]!=) flg = ; }
if(flg){
printf("%d", p[i]);
return ;
}
}
printf("-1");
return ;
}
codeforces 1025B Weakened Common Divisor(质因数分解)的更多相关文章
- CodeForces - 1025B Weakened Common Divisor
http://codeforces.com/problemset/problem/1025/B 大意:n对数对(ai,bi),求任意一个数满足是所有数对中至少一个数的因子(大于1) 分析: 首先求所有 ...
- codeforces#505--B Weakened Common Divisor
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- CF1025B Weakened Common Divisor 数学
Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input st ...
- CF #505 B Weakened Common Divisor(数论)题解
题意:给你n组,每组两个数字,要你给出一个数,要求这个是每一组其中一个数的因数(非1),给出任意满足的一个数,不存在则输出-1. 思路1:刚开始乱七八糟暴力了一下果断超时,然后想到了把每组两个数相乘, ...
- Codeforces #505(div1+div2) B Weakened Common Divisor
题意:给你若干个数对,每个数对中可以选择一个个元素,问是否存在一种选择,使得这些数的GCD大于1? 思路:可以把每个数对的元素乘起来,然后求gcd,这样可以直接把所有元素中可能的GCD求出来,从小到大 ...
- 【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] [题解] 求出第一个数对的两个数他们有哪些质因子. ...
- HDU - 1019 - Least Common Multiple - 质因数分解
http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...
- CF1025B Weakened Common Divisor【数论/GCD/思维】
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...
- CF1025B Weakened Common Divisor
思路: 首先选取任意一对数(a, b),分别将a,b进行因子分解得到两个因子集合然后取并集(无需计算所有可能的因子,只需得到不同的质因子即可),之后再暴力一一枚举该集合中的元素是否满足条件. 时间复杂 ...
随机推荐
- Spark学习笔记(一)——基础概述
本篇笔记主要说一下Spark到底是个什么东西,了解一下它的基本组成部分,了解一下基本的概念,为之后的学习做铺垫.过于细节的东西并不深究.在实际的操作过程中,才能够更加深刻的理解其内涵. 1.什么是Sp ...
- wepy怎么在生命周期中调用methods方法
很简单: 比如在 onLoad () { imgRemove(e) { this.methods.onRemove(e) } } 在methods中就可以直接调用属于它的方法, ...
- 初识Activiti工作流
一.背景介绍 公司最近接了一个监狱AB门系统的项目,在对项目进行调研时,发现客户的关注点主要是在AB门流程这块,项目大部分功能都是审批流程和单据流动状态等.而之前公司的项目关于流程主要都是在表中设置状 ...
- ODBC连接时报错不可识别的数据库格式
报这个错误是因为Acess的版本不同. 2003版本的Acess的数据连接字符串: string dataBasePath = @"C:/Users/user/Documents/Test. ...
- 七牛云 融合CDN测试域名 -> 融合CDN加速域名
七牛云 融合CDN测试域名 -> 融合CDN加速域名 本篇主要讲解 如何将七牛云融合CDN测试域名 切换到自定义的加速域名上去,为什么会写这篇是因为我收到了一封 [七牛云]测试域名回收通知的邮件 ...
- 使用vscode运行python出现中文乱码的解决方法
前提:自己安装了code runner的插件 快捷键Ctrl+Shift+P,打开设置Open Settings (JSON):
- UVA540 Team Queue——题解 by hyl天梦
UVA540 Team Queue 题解 题目描述:题目原题 https://vjudge.net/problem/UVA-540 Queues and Priority Queues are dat ...
- [bzoj3527] [洛谷P3338] [Zjoi2014]力
Description 给出n个数qi,给出Fj的定义如下: \[ F_j=\sum\limits_{i<j} \frac{q_iq_j}{(i-j)^2} - \sum\limits_{i&g ...
- 嵩天老师python网课爬虫实例1的问题和解决方法
一,AttributeError: 'NoneType' object has no attribute 'children', 网页'tbody'没有子类 很明显,报错的意思是说tbody下面没有c ...
- 16、python面对对象之类和继承
前言:本文主要介绍python面对对象中的类和继承,包括类方法.静态方法.只读属性.继承等. 一.类方法 1.类方法定义 使用装饰器@classmethod装饰,且第一个参数必须是当前类对象,该参数名 ...