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