题意:

给你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 ;
}

最新文章

  1. oracle远程连接配置
  2. TCP : two different sockets sharing a port?
  3. sqlserver数据库附加报错5120
  4. 代码开光,Orz
  5. C# IL DASM 使用
  6. Java事件总线
  7. 在scrollView中使用pageControl
  8. redis常用的命令总结
  9. ESP32搭建2.虚拟机与物理机实现文件传输
  10. Maven教程3(依赖管理)
  11. MATLAB 不能保存变量问题及解决办法
  12. 修改linux 最大文件限制数 ulimit
  13. T-SQL查询进阶--理解SQL Server中索引的概念,原理以及其他
  14. ios学习之UIWebView网页视图调整
  15. python 基础3 函数
  16. JS函数调用的四种方法
  17. [less]用webstorm自动编译less产出css和sourcemap
  18. Word2013文章如何直接发布到CSDN博客
  19. 解决ionic 2载入速度慢的问题
  20. win7下users用户文件转移到其他盘符

热门文章

  1. Java截图小程序源码
  2. enum sizeof typedef分析
  3. CF - 高精度 + 贪心
  4. mysql复习1
  5. Centos7 搭建Grafana+Jmeter+Influxdb 性能实时监控平台
  6. Jenkins-正则表达式提取Cookie
  7. 关于爬虫的日常复习(2)—— urllib库
  8. mysql 行增删改查
  9. ORM 效率补充
  10. 用Kolla在阿里云部署10节点高可用OpenStack