标签:ret 部分 ++ common typedef temp main turn gcd
http://codeforces.com/problemset/problem/1025/B
大意:n对数对(ai,bi),求任意一个数满足是所有数对中至少一个数的因子(大于1)
分析:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=150000+100; ll a[MAXN],b[MAXN]; int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lld %lld",&a[i],&b[i]); ll gcd=a[0]*b[0]/__gcd(a[0],b[0]); for(int i=1;i<n;i++) gcd=__gcd(gcd,a[i]*b[i]/__gcd(a[i],b[i])); if(gcd==1) { printf("-1\n"); return 0; } ll temp; for(int i=0;i<n;i++) { temp=__gcd(gcd,a[i]); if(temp>1){ gcd=temp; continue; } temp=__gcd(gcd,b[i]); if(temp>1) gcd=temp; } printf("%lld\n",gcd); return 0; }
CodeForces - 1025B Weakened Common Divisor
标签:ret 部分 ++ common typedef temp main turn gcd
原文地址:https://www.cnblogs.com/spzeno/p/10467084.html